This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XSL to Sort XML Doc return XML
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] XSL to Sort XML Doc return XML
- From: "MacEwan, James (Information Services)" <James dot MacEwan at investorsgroup dot com>
- Date: Fri, 1 Jun 2001 12:23:51 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Xiaocun and xsl-list,
I am a novice and thought I would try your solution for myself. I had to
wrap up your xsl a little bit and have produced the following two flavours
of code that work (one with for-each, the other with apply-templates).
for-each flavour:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<records>
<xsl:for-each select="records/record">
<xsl:sort select="."/>
<record><xsl:value-of select="."/></record>
</xsl:for-each>
</records>
</xsl:template>
</xsl:stylesheet>
apply-templates flavour:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="records">
<records><xsl:apply-templates><xsl:sort
select="."/></xsl:apply-templates></records>
</xsl:template>
<xsl:template match="record">
<record><xsl:value-of select="."/></record>
</xsl:template>
</xsl:stylesheet>
I am at a bit of loss as to which approach would be better (and I don't even
know how to name these two approaches). Can you recommend a reference/web
tutorial/whatever that will help me better understand the design patterns
being used and when to use which?
Thanks,
J.
> From: Xiaocun Xu [mailto:xiaocunxu@yahoo.com]
> Sent: Thursday, May 31, 2001 2:49 PM
> To: xsl-list@lists.mulberrytech.com
> Subject: Re: [xsl] XSL to Sort XML Doc return XML
> Doc ?
>
> Hi, Matt:
>
> This can be done pretty easily with xsl:sort,
> like:
> <records>
> <xsl:for-each select="records/record">
> <xsl:sort select="."/>
> <record><xsl:value-of select="."/></record>
> </xsl:for-each>
> </records>
James MacEwan
Software Developer
Investors Group Inc.
mailto:James.MacEwan@investorsgroup.com
v: (204) 956-8515
f: (204) 943-3540
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list