I am newbie to XSLT and fighting to get the right syntax for concatinating string in for-each loop. I have two variables declared depending on the condition need to concatenate a string to the variable.
-
Perhaps this link might help.Frankline– Frankline2012-01-17 14:44:45 +00:00Commented Jan 17, 2012 at 14:44
-
Please, edit the question and provide: 1. The source XML document (as small as possible). 2. The exact wanted result. 3. Any necessary rules for the transformation.Dimitre Novatchev– Dimitre Novatchev2012-01-17 15:21:50 +00:00Commented Jan 17, 2012 at 15:21
Add a comment
|
1 Answer
Here is a demonstration of string concatenation with an xsl:for-each and based on the value of a variable:
<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>
when this transformation is applied on the following XML document:
<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