Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath 如何消除所有<;标签/>;和所有属性="&引用;通过XSLT?_Xpath_Xslt 1.0 - Fatal编程技术网

Xpath 如何消除所有<;标签/>;和所有属性="&引用;通过XSLT?

Xpath 如何消除所有<;标签/>;和所有属性="&引用;通过XSLT?,xpath,xslt-1.0,Xpath,Xslt 1.0,在xsl:stylesheet中,我进行了这种“类似标识”的转换,以消除注释、空(终端)标记和空属性。。。但是第二个xsl:when不起作用 <xsl:template match="node()"> <xsl:choose> <xsl:when test="name()='p' and not(./*) and not(normalize-space(.))"></xsl:when> <xsl:when test="

xsl:stylesheet
中,我进行了这种“类似标识”的转换,以消除注释、空(终端)标记和空属性。。。但是第二个
xsl:when
不起作用

  <xsl:template match="node()">
  <xsl:choose>
    <xsl:when test="name()='p' and not(./*) and not(normalize-space(.))"></xsl:when>
    <xsl:when test="not(name()='img') and not(name()='br') and not(./*) and not(text())"
    ></xsl:when> <!-- this line NOT WORKS -->
    <xsl:otherwise><xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy></xsl:otherwise>
  </xsl:choose>
  </xsl:template>

  <xsl:template match="@*">
  <xsl:choose>
    <xsl:when test="not(normalize-space(.))"></xsl:when>
    <xsl:otherwise><xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy></xsl:otherwise>
  </xsl:choose>
  </xsl:template>

  <xsl:template match="comment()"></xsl:template>

在这个上下文中,谁来表示空标记的条件


PS:“空规则”是,我尝试使用它,但不明白为什么不起作用。

空元素是没有子节点的元素

模板匹配优先级是您的朋友。。。下面应该是符合您描述的标识样式表,以及我认为您正在使用图像和打断元素所做的工作

<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<!--toss these-->
<xsl:template match="comment() | 
                    *[not(node())] |
                    @*[not(normalize-space())]"/>

<!--preserve these-->
<xsl:template match="img|br" priority="1">
  <xsl:call-template name="identity"/>
</xsl:template>

<!--preserve everything else-->
<xsl:template match="@*|node()" name="identity">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

空元素是没有子节点的元素

模板匹配优先级是您的朋友。。。下面应该是符合您描述的标识样式表,以及我认为您正在使用图像和打断元素所做的工作

<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<!--toss these-->
<xsl:template match="comment() | 
                    *[not(node())] |
                    @*[not(normalize-space())]"/>

<!--preserve these-->
<xsl:template match="img|br" priority="1">
  <xsl:call-template name="identity"/>
</xsl:template>

<!--preserve everything else-->
<xsl:template match="@*|node()" name="identity">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>


这方面的唯一参考是邮件列表:D rtfm!顺便说一句,请接受回答。唯一的参考是邮件列表D rtfm!顺便说一句,请接受回答谢谢,这很有效!这是一个更好、更清洁的解决方案!关于我的测试。。。当我用
添加另一个模板时,函数
xslib::chgCase
使用DOM,它会破坏样式表中的一些“抛出案例”。。。但这是…的一些“副作用”。。。现在我被隔离了。非常感谢,它很有效!这是一个更好、更清洁的解决方案!关于我的测试。。。当我用
添加另一个模板时,函数
xslib::chgCase
使用DOM,它会破坏样式表中的一些“抛出案例”。。。但这是…的一些“副作用”。。。现在我被孤立了。