我试图仅替换节点中的一部分值。我在这里阅读了一些文章,它们似乎取代了整个字符串。
这是我拥有的;
<commands>
<command>chmod 550 OLDPATH/system</command>
<command>chmod 750 OLDPATH/system/config/home</command>
</commands>
这就是我想要的;
<commands>
<command>chmod 550 NEWPATH/system</command>
<command>chmod 750 NEWPATH/system/config/home</command>
</commands>
答案 0 :(得分:3)
从技术上讲,您无法替换XSLT中的任何内容。但是,当您替换节点的整个值时,可以使用字符串函数在构建新值时使用要替换的值的一部分。
例如,将以下模板应用于您的示例:
<xsl:template match="command">
<xsl:copy>
<xsl:value-of select="substring-before(., 'OLDPATH')" />
<xsl:text>NEWPATH</xsl:text>
<xsl:value-of select="substring-after(., 'OLDPATH')" />
</xsl:copy>
</xsl:template>
会导致:
<command>chmod 550 NEWPATH/system</command>
<command>chmod 750 NEWPATH/system/config/home</command>