I am looking at a similar problem to what was covered here
Transforming List into a 2-D Table
but with a slight wrinkle. My XML is not in any particular order and I would like to sort it for display. For example my XML is
<items>
<item>A</item>
<item>C</item>
<item>E</item>
<item>B</item>
<item>D</item>
<!-- ... any number of item nodes ... -->
<item>
and I want my output to be (where I am ignoring the non-named nodes for illustrative purposes)
<table>
<tr>
<td>A</td>
<td>C</td>
<td>E</td>
</tr>
<tr>
<td>B</td>
<td>D</td>
<td />
</tr>
</table>
The XSL I am basing this off is from the above link (I need to use XSL 1.0):
<xsl:template match="/*">
<table>
<xsl:call-template name="make-columns">
<xsl:with-param name="nodelist" select="item"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="make-columns">
<xsl:param name="nodelist"/>
<xsl:param name="columns-number" select="3"/>
<tr>
<xsl:apply-templates select="$nodelist[
not(position() > $columns-number)
]"/>
<xsl:if test="count($nodelist) < $columns-number">
<xsl:call-template name="empty-cells">
<xsl:with-param name="finish"
select="$columns-number - count($nodelist)"/>
</xsl:call-template>
</xsl:if>
</tr>
<!-- If some nodes are left, recursively call current
template, passing only nodes that are left -->
<xsl:if test="count($nodelist) > $columns-number">
<xsl:call-template name="make-columns">
<xsl:with-param name="nodelist" select="$nodelist[
position() > $columns-number
]"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="item">
<td>
<xsl:apply-templates/>
</td>
</xsl:template>
<xsl:template name="empty-cells">
<xsl:param name="finish"/>
<td/>
<xsl:if test="not($finish = 1)">
<xsl:call-template name="empty-cells">
<xsl:with-param name="finish" select="$finish - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
I have tried inserting commands within the various apply-templates but that doesn't work.
ideas?
Jeff
Update from comments
I want to output a multicolum table with 3 columns where the entries are in alphabetical order vertically
This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Update: Now, with new requeriment explained, this stylesheet:
Output:
Note:
node-set
extension function for a two phase transformation.