问题在文字 我需要插入一个字符串在其他字符串,我找到一个特殊的字符串。这些特殊字符串的定义在节点集中。最接近的通用解决方案是执行多重替换,并用插入的字符串替换匹配的特殊字符串与特殊字符串连接。我已经搜索了一个解决方案,但没有找到任何工作。XSLT 1.0:多个字符串替换的命名模板?
示例。 输入XML:
<root name ="theTop.">
<string>Here are some silly words</string>
<string>where I would like</string>
<other>
<string>to append other silly words</string>
</other>
<words>
<word name="word"/>
<word name="silly"/>
</words>
</root>
输出XML:
<root name ="theTop.">
<string>Here are some theTop.silly theTop.words</string>
<string>where I would like</string>
<other>
<string>to append other theTop.silly theTop.words</string>
</other>
<words>
<word name="word"/>
<word name="silly"/>
</words>
</root>
我还没有想出什么有用呢。这是我所想象的skelleton如何能像“素描”:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:variable name="append" select="/root/@name"/>
<xsl:variable name="places" select="/root/words/word/@name"/>
<!-- Identity rule.-->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//string">
<xsl:call-template name="replace-multiple">
<xsl:with-param name="text" select="."/>
<xsl:with-param name="replace" select="$places"/>
<xsl:with-param name="with" select="concat($append,$places)"/>
</xsl:call-template>
</xsl:template>
Obvioulsy这不起作用。它不迭代节点集$位置,我没有命名模板replace-multiple替换多个不同的字符串。
任何想法?
您的输入有例如' word ''while your XSLT choose such。 '/ root/words/word/@ name',这对我没有意义。然后期望的结果有'',你想转换这些元素吗?请澄清。 –
啊,对不起。复制粘贴错误。现在修复。 –