I'm creating a csv from an xml file using xslt. The xml document I'm actually working with is enormous, but I am stuck on an issue and have a simplified example below.
I'm attempting to create something like this
Item1,Item2,Item3,Item4,Item5,
1,2,3,,,
1,2,3,4,,
1,2,3,4,5,
1,2,,,,
My highest item count is how many column names I will need. I will then need each items group to print out its values, and also keep iterating and plugging in empty values up to the highest count. I need to do this because I have no idea how many items in a group I will have, so I want to eventually create a db table that has up to the highest count of items... Its confusing and hard and that is why I need help.
My xml
<example>
<items>
<item>1</item>
<item>2</item>
<item>3</item>
</items>
<items>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</items>
<items>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
</items>
<items>
<item>1</item>
<item>2</item>
</items>
My xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/" name="test">
<xsl:for-each select="example/items">
<xsl:sort select="count(item)" data-type="number" order="descending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="count(item)"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
So far I've been able to get the number of the highest count out of all the groups, which is 5. Can I some how use this number to generate the rest of my output?
Any help would be greatly appreciated :)