简体   繁体   English

xsl:copy-of排除父项并替换

[英]xsl:copy-of excluding parent together with replace

Good afternoon! 下午好! It's been a while since I've done XSLT and am a bit stumped. 自从我完成XSLT以来已经有一段时间了,有点困惑。 Trying to achieve the following: 尝试实现以下目标:

When applied to the following xml.. 当应用于以下xml ..

<tag>
  content
  <br />
</tag>

would produce this result: 会产生以下结果:

modified content
<br />

In other words, I'm trying to grab/output all contents on the main tag, including HTML but with a modified content item. 换句话说,我正在尝试获取/输出主标签上的所有内容,包括HTML,但内容项已修改。 Just selecting the element content is dead simple with a <xsl:copy-of select="./node()"/> and so is replacing the "content" with something else, but I can't seem to figure out how to combine the two. 仅使用<xsl:copy-of select="./node()"/>选择元素内容非常简单,因此用其他内容替换“ content”,但是我似乎无法弄清楚如何结合两者。 I'm also using XSLT 1.0 as well. 我也正在使用XSLT 1.0。

Use 采用

<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>

Of course if any first child text node of tag elements need to be manipulated then you could change the third template to say 当然,如果需要操纵tag元素的第一个子文本节点,则可以将第三个模板更改为

<xsl:template match="tag/text()[1]">
  <xsl:value-of select="concat('modified ', .)"/>
</xsl:template>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM