Subject:Incrementing a variable qname in a for-each? Author:Peter Bartell Date:02 May 2006 01:53 PM
First time poster and relative newbie to XSLT. I am trying to load a list of variables, whose names increment by one, with a group of values into a CSV string.
<xsl:for-each select="//topic">
<xsl:variable name="var1"><!-- this needs to increment up by 1 on each pass -->
<xsl:value-of select="element1"/><xsl:text>,</xsl:text>
<xsl:value-of select="element2"/><xsl:text>,</xsl:text>
<xsl:value-of select="element3"/><xsl:text>,</xsl:text>
<xsl:value-of select="element4"/>
</xsl:variable>
</xsl:for-each>
I need to somehow keep these variable values 'alive' for later processing. I have looked for examples of this, but it seems that a Qname cannot be updated this way. Any suggestions are very much appreciated! Thanks.
Subject:Incrementing a variable qname in a for-each? Author:Peter Bartell Date:02 May 2006 04:07 PM
Hi Srini,
Thanks for the reply. I realize that variables cannot be updated. That's why I wanted to be able to make a new variable for each pass.
What I need to do is find several elements in many topics, group them by one of the elements where the contents are the same, and then render them in HTML. I had thought if I could load them into some sort of array of many variables and then work with the variables, I could accomplish this.
I have seen some XSLT using <xsl:value-of select=key(... that looks like it might be what I'm looking for, but I really don't understand it. Any guidance is appreciated. Thanks.
As you can see, when element1 content is the same, it groups the rest of the elements' content from the other topics into the same html row. Thanks again for your help! Let me know if you need anything more.
Subject:Incrementing a variable qname in a for-each? Author:Peter Bartell Date:03 May 2006 09:16 AM
Thank you all for your help! First I will try to understand the XPath, then I will try integrating it with the rest of my code soon. And sorry about the non-wellformed example; I just sent a snippet, but I should have stated that. Thanks again!
Subject:Incrementing a variable qname in a for-each? Author:Peter Bartell Date:03 May 2006 05:41 PM
After trying to implement the XSL, I see that I did a bad job of relating my situation. I gave you example XML that was not completely useful. The elements I need to place in rows in the HTML are not siblings, therefore the position() won't work. Instead the elements are all children, ancestors, or ancestor attribute values of topic. I had expected to explicitly define those at some point in the code, but I don't think position lets me do that.
Naturally I do not expect a complete solution, but I have included a real XML instance and here are the values I need to extract relative to their parent topic.