Eric said:
<element name="sam" />
<element name="bob" />
<element name="alice" />
<element name="mary" />
<element name="fred" />
<element name="barbara" />
and you want to create a 2-column SORTED html table with
the names, thus if we had the 6 elements above
alice fred
barbara mary
bob sam
Of course you can have any number of elements....
I have tried a few techniques but to no avail...I am using
XSLT 1.1 on Windows.
First time I hear about XSLT 1.1. Hmmm...
From XSL Transformations (XSLT) Version 1.1 W3C Working
Draft 24 August 2001:
As of 24 August 2001 no further work on this draft is
expected. The work on XSLT 2.0 identified a number of
issues with the approaches being pursued in this document;
solutions to the requirements of XSLT 1.1 will be
considered in the development of XSLT 2.0 [XSLT20REQ].
Other than this paragraph, the document is unchanged from
the previous version.
I assume something this basic is doable.
<xsl:stylesheet version="1.0"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*[element]">
<xsl
aram name="cols" select="2"/>
<xsl:variable name="elements" select="element"/>
<xsl:variable name="elt-cnt"
select="count($elements)"/>
<xsl:apply-templates select="$elements"
mode="row-start">
<xsl:sort select="@name" order="ascending"/>
<xsl:with-param name="elements" select="$elements"/>
<xsl:with-param name="rows"
select="$elt-cnt div $cols"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="element" mode="row-start">
<xsl
aram name="elements"/>
<xsl
aram name="rows"/>
<xsl:if test="position()<=$rows">
<row>
<xsl:apply-templates select="."/>
<xsl:apply-templates select="$elements"
mode="row">
<xsl:sort select="@name" order="ascending"/>
<xsl:with-param name="rows" select="$rows"/>
<xsl:with-param name="row" select="position()"/>
</xsl:apply-templates>
</row>
</xsl:if>
</xsl:template>
<xsl:template match="element" mode="row">
<xsl
aram name="rows"/>
<xsl
aram name="row"/>
<xsl:if
test=
"
(((position()-1) mod $rows)=($row -1)) and
(position()!=$row)
">
<xsl:apply-templates select="."/>
</xsl:if>
</xsl:template>
<xsl:template match="element">
<cell>
<xsl:copy-of select="@name"/>
</cell>
</xsl:template>
</xsl:stylesheet>
Is it clunky? Sure is. Does it work? Sure does.