sconover@groundswell.net schreibt:
>
><rows>
> <row>apple</row>
> <row>orange</row>
> <row>banana</row>
> <row>grape</row>
></rows>
>
>I'd like to put them in a hierarchy:
think that would do, idea taken from XSLT Programmers reference by M. Kay
p.172, who shows
a similar example about list processing.
The trick is to call a named template recursivly.
This template cracks up the list in first and rest (car/cdr in lisp
speaking). First is given to
the output and rest is passed to the template as parameter again.
>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="rows">
<doc>
<xsl:call-template name="stepin">
<xsl:with-param name="listofnodes" select="row"/>
</xsl:call-template>
</doc>
</xsl:template>
<xsl:template name="stepin">
<xsl:param name="listofnodes"/>
<xsl:if test="$listofnodes">
<item>
<xsl:value-of select="$listofnodes[1]" />
<xsl:call-template name="stepin">
<xsl:with-param name="listofnodes"
select="$listofnodes[position()!=1]"/>
</xsl:call-template>
</item>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
>
Manfred Knobloch
Kompetenzzentrum für Multimedia und Telematik
am DIFF
Konrad Adenauer Str. 40
72072 Tübingen
tel: ++49 (0)7071 / 979 232
fax: ++49 (0)7071 / 979 322
email: manfred_knobloch@diff.uni-tuebingen.de
www: http://kmmt.diff.uni-tuebingen.de
|