xsl-list
[Top] [All Lists]

RE: How to sort?

2004-10-15 01:22:54
Hi,

Most probably the second predicate, i.e.

     <xsl:for-each select="Article[(_at_)info = 'main']">

only processes the main ones.

Cheers,

Jarno - Velvet Acid Christ: Futile (Resisted mix by Funker Vogt)

-----Original Message-----
From: ext Mike G [mailto:row(_dot_)filter(_at_)gmail(_dot_)com]
Sent: 15 October, 2004 11:16
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] How to sort?


How do I get Only one chapter e.g. chapter="2" instead of 
getting all chapters
in kombination with implementation above?

-Mike


On Fri, 15 Oct 2004 10:07:34 +0200, Mike G 
<row(_dot_)filter(_at_)gmail(_dot_)com> wrote:
Yeah, this works with some modification.

<xsl:apply-templates select="Document[Article/@info = 'main' or
Article/@filter = 'food']"/>

thanx!

-Mike

On Thu, 14 Oct 2004 15:06:16 +0300, 
jarno(_dot_)elovirta(_at_)nokia(_dot_)com


<jarno(_dot_)elovirta(_at_)nokia(_dot_)com> wrote:
Hi,

What I do now, is choose all Article elements that 
contain info="main"
and info="sub" attributes and then sort everything by state="n"
attribute.

An Article cannot have two info attributes, thus the 
above condition can never be true in XML.

Is it possible to implement an sorting option that 
enables Article
elements where filter="food" to be placed on the top of 
the Article
list, that is giving them higher priority in sort than 
the previous
value of state="n".

so the XML output will look like:

<?xml version="1.0"?>
<Documents>
      <Document title="1" chapter="i" href="file1.xml" 
filter="food">
              <Article title="1.2" info="main" filter="food"/>
              <Article title="1.3" info="main" filter="drink"
state="2"/>
      </Document>

      <Document title="2" chapter="ii" href="file2.xml"
filter="drink">
                     <Article title="2.2" info="main" 
filter="food"/>
                     <Article title="2.1" info="main"
filter="drink" state="1"/>
      </Document>

      <Document title="4" chapter="2" href="file2.xml" 
filter="">
              <Article title="3.2" info="main" filter="food"/>
      </Document>
</Documents>

 <xsl:template match="Documents">
   <xsl:copy>
     <xsl:apply-templates select="Document[Article/@info 
= 'main' and Article/@info = 'sub']"/>
   </xsl:copy>
 </xsl:template>
 <xsl:template match="Document">
   <xsl:copy>
     <xsl:copy-of select="@*"/>
     <xsl:for-each select="Article[(_at_)info = 'main']">
       <xsl:sort select="@filter ='food'" 
data-type="number" order="descending"/>
       <xsl:sort select="@state" data-type="number"/>
       <xsl:copy-of select="."/>
     </xsl:for-each>
   </xsl:copy>
 </xsl:template>

I'm not sure exactly how you wanted the info attribute 
handled, because you desired output doesn't use Articles with 
"sub" info. Anyhow, this produces the desired output. The

 <xsl:sort select="@filter ='food'" data-type="number" 
order="descending"/>

sort condition basically works so that the "@filter = 
'food'" expression will either return boolean true or false, 
which will be cast to number 1 or 0, respectively, and that 
gives you the sort key value.



Cheers,

Jarno - Lisa Lashes: Hard Mix


--+------------------------------------------------------------------
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>
--+--




--

[row.filter]



-- 

[row.filter]

--+------------------------------------------------------------------
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>
--+--



<Prev in Thread] Current Thread [Next in Thread>