Subject: Re: [xsl] muliple level sorting using xsl:sort From: Aravind J <aravindjp@xxxxxxxxx> Date: Mon, 5 Sep 2005 04:44:57 -0700 (PDT) |
Hi , Thank you very much for your reply, I still didn't get how it will sort , could you pls tell me how it will work especially why we need <xsl:copy-of select="code/name"/> <xsl:apply-templates select="child"/> in for-each loop ? --- Joris Gillis <roac@xxxxxxxxxx> wrote: > Hi, > > Tempore 11:19:01, die 09/05/2005 AD, hinc in > xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Aravind J > <aravindjp@xxxxxxxxx>: > > > when i tried to sort the data using > > <xsl:for-each select="Part"> > > <xsl:sort data-type="number" > > select="descendant-or-self::code/name"/> it is > doing e > > first level sorting correctly, ie data is sorted > in > > 1,2,5 order (code/name) . but sub parts of <part> > 5 ie > > 5-3 and 5-4 are not getting sorted , similarly for > > children of 5-4 also. > > > > Any idea how we can sort sub parts ie (child > <Part> ) > > also in this case . > > Somehow, you'd need to extract the last number of > the 'n(-n)*' sequence, > One possible solution is to rely on the fact that > the sequence is the same as the previous level + > '-n' : > > "substring(code/name,string-length(ancestor::Part[1]/code/name) > + 1 + boolean(ancestor::Part))" > > e.g. this stylesheet: > > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > <xsl:output method="xml" indent="yes"/> > > <xsl:template match="AAAA|child"> > <level> > <xsl:for-each select="Part"> > <xsl:sort data-type="number" > > select="substring(code/name,string-length(ancestor::Part[1]/code/name) > +1+boolean(ancestor::Part))"/> > <xsl:copy-of select="code/name"/> > <xsl:apply-templates select="child"/> > </xsl:for-each> > </level> > </xsl:template> > > </xsl:stylesheet> > > Will return this result: > <level> > <name>1</name> > <name>2</name> > <name>5</name> > <level> > <name>5-3</name> > <name>5-4</name> > <level> > <name>abc</name> > <name>def</name> > </level> > </level> > </level> > > > regards, > -- > Joris Gillis > (http://users.telenet.be/root-jg/me.html) > Ceterum censeo XML omnibus esse utendum > > ______________________________________________________ Click here to donate to the Hurricane Katrina relief effort. http://store.yahoo.com/redcross-donate3/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] muliple level sorting usi, Joris Gillis | Thread | Re: [xsl] muliple level sorting usi, Joris Gillis |
Re: [xsl] Terminate <xsl:for-each>, aaron apigo | Date | [xsl] Immediate uncle, Trevor Nicholls |
Month |