xml文件-
<mydocument>
<ol outputclass="abc">
<li>
<p>
This is a regular ol,
and outputclass= abc without linum.
</p>
</li>
<li>
<p>This is a regular ol,
and outputclass= abc without linum.</p>
</li>
</ol>
<ol outputclass="static">
<li>
<linum>3.</linum>
<p>
Here we use linum with an ol and outputclass=”static”.
</p>
</li>
<li>
<linum>4.</linum>
<p>Here we use linum with an ol and outputclass=”static”.
</p>
</li>
</ol>
<ol outputclass="static">
<li>
<p>This is ol with outputclass as static without linum element
</p>
</li>
</ol>
</mydocument>
Xsl文件-
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="@outputclass">
<xsl:attribute name="outputclass">
<xsl:choose>
<xsl:when test=". ='static'">
<xsl:text>continue()</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
<!-- drop linum elements and its value -->
<xsl:template match="ol/li/linum">
</xsl:template>
</xsl:stylesheet>
如果在ol / li标记中找到了linum元素,并且我也想完全删除linum标记,我试图将static的outputclass值替换为continue()。我可以为第二个ol实现此目的,但它也可以替换第三个ol outputclass值,理想情况下不应该这样做,因为它内部没有linum元素。
我得到的输出-
<mydocument>
<ol outputclass="abc">
<li>
<p>
This is a regular ol,
and outputclass= abc without linum.
</p>
</li>
<li>
<p>This is a regular ol,
and outputclass= abc without linum.
</p>
</li>
</ol>
<ol outputclass="continue()">
<li>
<p>Here we use linum with an ol and outputclass=”static”.
</p>
</li>
<li>
<p>Here we use linum with an ol and outputclass=”static”.
</p>
</li>
</ol>
<ol outputclass="continue()">
<li>
<p>This is ol with outputclass as static without linum element
</p>
</li>
</ol>
</mydocument>
所需的输出-
<mydocument>
<ol outputclass="abc">
<li>
<p>
This is a regular ol,
and outputclass= abc without linum.
</p>
</li>
<li>
<p>This is a regular ol,
and outputclass= abc without linum.
</p>
</li>
</ol>
<ol outputclass="continue()">
<li>
<p>Here we use linum with an ol and outputclass=”static”.
</p>
</li>
<li>
<p>Here we use linum with an ol and outputclass=”static”.
</p>
</li>
</ol>
<ol outputclass="static">
<li>
<p>This is ol with outputclass as static without linum element
</p>
</li>
</ol>
</mydocument>
答案 0 :(得分:0)
对于属性,请使用模板
<xsl:template match="ol[.//linum]/@outputclass[. = 'static']">
<xsl:attribute name="outputclass">continue()</xsl:attribute>
</xsl:template>
连同其他两个模板。