下午好!我已经有一段时间没有做XSLT了,有点不知所措。尝试实现以下目标:
应用于以下xml时。。
<tag>
content
<br />
</tag>
将产生以下结果:
modified content
<br />
换句话说,我试图获取/输出主标记上的所有内容,包括HTML,但内容项已修改。用<xsl:copy-of select="./node()"/>
选择元素内容非常简单,用其他东西替换"内容"也是如此,但我似乎不知道如何将两者结合起来。我也在使用XSLT1.0。
使用
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="tag">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="tag/text()[contains(., 'content')]">
<xsl:value-of select="concat('modified ', .)"/>
</xsl:template>
当然,如果需要操作tag
元素的任何第一个子文本节点,那么您可以将第三个模板更改为
<xsl:template match="tag/text()[1]">
<xsl:value-of select="concat('modified ', .)"/>
</xsl:template>