This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: xsl sorting


Heppa,


> If there is several sorting orders, they are all applied and not
> only the last one. For example if there is xml file that includes
> severals sets like:
> 
> <Subject id="0000000001" id2="001" id3="001">Juu juu</Subject>
> <Subject id="0000000001" id2="002" id3="002">RE:Juu juu</Subject>
> <Subject id="0000000001" id2="002" id3="001">RE:Juu juu</Subject>
> 
> and sets are sorted:
> <xsl:sort select="Subject/@id" order="ascending" /> 
> <xsl:sort select="Subject/@id2" order="ascending" />
> <xsl:sort select="Subject/@id3" order="ascending" />
> 
> So the result would be:
> <Subject id="0000000001" id2="001" id3="001">Juu juu</Subject>
> <Subject id="0000000001" id2="002" id3="001">RE:Juu juu</Subject>
> <Subject id="0000000001" id2="002" id3="002">RE:Juu juu</Subject>
> 
> Right?

Right, but make sure when you're using the sort instruction that your context node is the corrent one for the sort select expressions. If you have 

  <xsl:for-each select="Subject">
    <xsl:sort select="Subject/@id" order="ascending" /> 
    <xsl:sort select="Subject/@id2" order="ascending" />
    <xsl:sort select="Subject/@id3" order="ascending" />
    <xsl:copy-of select="." />    
  </xsl:for-each>

that will not work, because the Subject doesn't have a Subject child. Instead use

<xsl:template match="f">
  <xsl:for-each select="Subject">
    <xsl:sort select="@id" order="ascending" /> 
    <xsl:sort select="@id2" order="ascending" />
    <xsl:sort select="@id3" order="ascending" />
    <xsl:copy-of select="." />    
  </xsl:for-each>
</xsl:template>

Cheers,

Santtu


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]