xsl-list
[Top] [All Lists]

Re: How to sort?

2004-10-14 02:17:44
ok.

If this is the XML with previously missing root-elements

<Documents>
       <Document title="1" chapter="i" href="file1.xml" filter="food">
               <Article title="1.1" info="sub" filter="drink" state="1"/>
               <Article title="1.2" info="main" filter="food" state="3"/>
                           <Article title="1.3" info="main" filter="drink" 
state="2"/>
       </Document>
       <Document title="2" chapter="ii" href="file2.xml" filter="drink">
               <Article title="2.1" info="main" filter="drink" state="1"/>
               <Article title="2.1" info="sub" filter="drink" state="3"/>
               <Article title="2.2" info="main" filter="food" state="2"/>
       </Document>
       <Document title="3" chapter="1" href="file2.xml" filter="">
               <Article title="3.1" info="sub" filter="drink" state=""/>
               <Article title="3.2" info="child" filter="" state="8"/>
       </Document>
       <Document title="4" chapter="2" href="file2.xml" filter="">
               <Article title="3.1" info="sub" filter="drink" state=""/>
               <Article title="3.2" info="main" filter="food" state="1"/>
       </Document>
</Documents>


could this be correct XSLT for my output. Could you check it? It runs
very slow for some reason.

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

thanx.

Mike


On Thu, 14 Oct 2004 11:45:38 +0300, jarno(_dot_)elovirta(_at_)nokia(_dot_)com
<jarno(_dot_)elovirta(_at_)nokia(_dot_)com> wrote:
Hi,

I want pick only Article elements where attribute info="main"

info-attribute is not located on the Document level, only on
Article level,
so when info="main" located it should be placed in the same
originating Document node
wheter info-atribute is located on Document level or not.

I need to order output XML by Chapter, chapter-attribute, on
Document-level. (i,ii,1,2 ... n)

Then I need to sort the output on Article level by state, ascending.

the output XML should look like this


<?xml version="1.0"?>

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

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

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

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

Note that your output is not well-formed XML and the stylesheet above will 
recreate the output example.

Cheers,

Jarno - Seabound: Contact (Assemblage 23 remix)

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


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