tags:

views:

56

answers:

1
<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

+1  A: 

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>
Mattio
darn I took too long...
Matthew Whited
Unless something has changed since I was involved in XSLT, the pattern is usually to test for position() > 1 and prefix it, as that is cheaper to calculate for the XSLT engine. The last() function requires the XSLT engine to look ahead and find the last match and see if the current one is the last, something you don't want to do.
Timothy Walters