Subject: Re: [xsl] XSL to Sort XML Doc return XML From: Xiaocun Xu <xiaocunxu@xxxxxxxxx> Date: Fri, 1 Jun 2001 11:46:51 -0700 (PDT) |
Hi, James: I noticed that you are not the original poster who were asking the sorting question, did you had similar problem you are trying to solve? If you have not yet noticed, the original poster later added more complexity to the question and the appropriate answer has changed to: <records> <xsl:for-each select="records/record"> <xsl:sort select="@attribute1"/> <xsl:copy-of select="."/> </xsl:for-each> </records> In his case, he wants the exact copies of the original record elements, so copy-of is more appropriate than value-of. Now to your question about which approaches you have shown is more appropriate. In general, the approach using apply-templates is more formal, modular and extensible. If you have other siblings besides record element you need to process, use apply-templates can handle it more clearly. But if only record element is processed, then just plain for-each is clear enough. As for reference on design pattern, a good place to start would be the Design Pattern section in the FAQ: http://www.dpawson.co.uk/xsl/N169.html Hope this helps, Xiaocun --- "MacEwan, James (Information Services)" <James.MacEwan@xxxxxxxxxxxxxxxxxx> wrote: > 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 > __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSL to Sort XML Doc retur, MacEwan, James (Info | Thread | [xsl] How to process elements with , Mohammed Rahman |
Re: [xsl] Inserting Elements with X, David Carlisle | Date | [xsl] How to process elements with , Mohammed Rahman |
Month |