我是XSLT的新手,并努力获得正确的语法,以便在for-each循环中合并字符串。我声明了两个变量,具体取决于将字符串连接到变量的条件。
答案 0 :(得分:2)
以下是使用xsl:for-each
并基于变量值的字符串连接的演示:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vOddEven" select="1"/>
<xsl:template match="/*">
<xsl:for-each select="num[. mod 2 = $vOddEven]">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
将此转换应用于以下XML文档:
<nums>
<num>01</num>
<num>02</num>
<num>03</num>
<num>04</num>
<num>05</num>
<num>06</num>
<num>07</num>
<num>08</num>
<num>09</num>
<num>10</num>
</nums>
the wanted result (concatenation of all numbers that have the same "oddness" as the variable
$ vOddEven ) is produced
:
0103050709