xsl-list
[Top] [All Lists]

Re: muliple level sorting using xsl:sort

2005-09-05 04:44:57
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(_at_)pandora(_dot_)be> wrote:

Hi,

Tempore 11:19:01, die 09/05/2005 AD, hinc in
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Aravind J
<aravindjp(_at_)yahoo(_dot_)com>:

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


--~------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





        
                
______________________________________________________
Click here to donate to the Hurricane Katrina relief effort.
http://store.yahoo.com/redcross-donate3/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--