1

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.

2
  • Perhaps this link might help. Commented 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. Commented Jan 17, 2012 at 15:21

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.