|
Subject: AW: [xsl] sorting AND copying of XML via XSL From: "Hendrik Beck \(Computation SIS GmbH\)" <hendrik.beck@xxxxxxxxxxxxxxxxxx> Date: Tue, 9 Sep 2003 18:27:40 +0200 |
Hi Marcel,
> Now I want to sort the bar elements and then the item elements
according to their Id's, and finally output
> the entire document sorted, e.g.
Think, there are better and shorter implementations do this, but this
might be one way to come by:
<xsl:output method="xml"/>
<xsl:template match="/foo">
<xsl:element name="foo">
<xsl:for-each select="bar">
<xsl:sort select="@id" order="ascending"></xsl:sort>
^^^^^^^^^^^
<xsl:element name="bar">
<xsl:attribute name="id"><xsl:value-of
select="@id"/></xsl:attribute>
<xsl:for-each select="item">
<xsl:sort select="@id"
order="ascending"></xsl:sort>
^^^^^^^^^^^
<xsl:element name="item">
<xsl:attribute
name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:value-of
select="item"/>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
Just put two sorted for-each-loops together and produce the output via
<xsl:element> and <xsl:attribute>. This produces the exactly the xml you
wanted. Or what else problem did you have with it?
Hendrik Beck
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] sorting AND copying of XML vi, marcel salathe | Thread | Re: [xsl] sorting AND copying of XM, Mukul Gandhi |
| [no subject], David Carlisle | Date | Re: [xsl] formatting xml output: in, Wendell Piez |
| Month |