Subject: Re: [xsl] XSL to Sort XML Doc return XML From: "MacEwan, James (Information Services)" <James.MacEwan@xxxxxxxxxxxxxxxxxx> Date: Fri, 1 Jun 2001 12:23:51 -0500 |
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@xxxxxxxxx] > Sent: Thursday, May 31, 2001 2:49 PM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > 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@xxxxxxxxxxxxxxxxxx v: (204) 956-8515 f: (204) 943-3540 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Inserting Elements with X, Joerg Pietschmann | Thread | Re: [xsl] XSL to Sort XML Doc retur, Xiaocun Xu |
[xsl] Inserting Elements with XSL, Joerg Pietschmann | Date | Re: [xsl] Inserting Elements with X, David Carlisle |
Month |