Reputation: 1919
<data>
<Attributes>
<Attribute name='somethingelse' value='blah'/>
<Attribute name='forms'>
<List>
<String>xform</String>
<String>yform</String>
</List>
</Attribute>
</Attributes>
</data>
I am already parsing the xslt at Attributes level, so I can get the value blah by just doing <xsl:value-of select="Attribute[@name='somethingelse']/attribute::value"/>
how do i do a select for the forms which has 2 strings xform and yform. I would like to get xform and yform on a same line. From other thread someone gave me the following code:
<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>
I am not sure how to put it all together.My goal is to have a output like:
blah,xform|yform
Upvotes: 0
Views: 1078
Reputation: 2309
You can also assign to a single variable like so:
<xsl:variable name="strings">
<xsl:value-of select="concat(String[1],String[2],String[3])" />
</xsl:variable>
It doesn't matter whether the 3rd string exists. This is kind of a hack and I actually hardcoded 10 it my code adding '###' between each, so that I could run 'contains($strings, '###Keyword'), which is basically checking if any of the Strings started with a specific string.
Upvotes: 0
Reputation: 60190
Not sure if I got your question right, but I guess that should output what you want:
<xsl:template match="/">
<xsl:apply-templates select="//Attributes"/>
</xsl:template>
<xsl:template match="Attributes">
<xsl:value-of select="Attribute[@name='somethingelse']/@value"/>
<xsl:text>,</xsl:text>
<xsl:for-each select="Attribute[@name='forms']/List/String">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">|</xsl:if>
</xsl:for-each>
</xsl:template>
Upvotes: 1