user140736
user140736

Reputation: 1919

parsing multiple lines in 1 line in XSLT

<xml>
   <data>
     <Attribute name='forms'>
        <List>
          <String>xform</String>
          <String>yform</String>
        </List>
      </Attribute>
    </data>
  </xml>

How would I set my xslt to get all the values in the List. So I would like to output both values in 1 line seperated by |. For ex.

xform|yform

Upvotes: 0

Views: 449

Answers (1)

Mattio
Mattio

Reputation: 2032

This is just one way, assuming the simple input example.

<xsl:template match="/">
  <xsl:for-each select="//String">
    <xsl:value-of select="."/><xsl:if test="not(position() = last())">|</xsl:if>
  </xsl:for-each>
</xsl:template>

Here's a more specific template rule if I understand the comment you added. It would be great if the person who commented about the usage of last() would post a sample, too.

<xsl:template match="Attribute[@name='forms']">
  <xsl:for-each select="List//String">
    <xsl:value-of select="."/><xsl:if test="not(position() = last())">|</xsl:if>
  </xsl:for-each>
</xsl:template>

Upvotes: 1

Related Questions