I would like to apply a XSL template to a portion of the XML and copy the rest unmodified in the result XML.
For the time being I'm doing something that works.
<xsl:template match="yt:bold">
<xsl:choose>
<xsl:when test="ancestor::ReportContent"> //I keep the ReportContent u开发者_如何学运维nchanged
<xsl:copy><xsl:copy-of select="@*"/>
<xsl:apply-templates />
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<b>
<xsl:apply-templates />
</b>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
But I'm doing this for each template... and I am sure there is a more elegant way to do this.
I tried to copy portion of the XML using this template:
<xsl:template match="ReportContent">
<xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates select="???" /></xsl:copy>
</xsl:template>
But I apply all the other templates when copying... and I don't want that.
So is there a more elegant way to do what I want to do?
Thanks in advance.
Is this what you're trying to do?
<xsl:template match="yt:bold[not(ancestor::ReportContent)]">
<b>
<xsl:apply-templates />
</b>
</xsl:template>
Or perhaps
<xsl:template match="ReportContent">
<xsl:copy-of select="."/>
</xsl:template>
?
精彩评论