[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: sorting and numbering

Subject: Re: sorting and numbering
From: Jörg Heinicke <Joerg.Heinicke@xxxxxx>
Date: Mon, 26 Nov 2001 13:56:27 +0100 (MET)
order by apply templates
Why are you using number when you can use position? In your case number is
not necessary

<xsl:template match="body">
    <xsl:apply-templates select="para[@order]">
        <xsl:sort select="@order"/>
    </xsl:apply-templates>
</xsl:template>

And as you can see you don't need <xsl:for-each> for sorting. It works on
<xsl:apply-templates> too.

<xsl:template match="para">
    <xsl:variable name="pos" select="position()"/>
    <xsl:value-of select="concat($pos, ' ', text())"/>
    <xsl:for-each select="para">
        <xsl:value-of select="concat($pos, '.', position(), ' ', text())"/>
    </xsl:for-each>
</xsl:template>

Hope this helps,

Joerg

> I am able to sort and do multi-level numbering with code
> as following but cannot get both do work appropriately
> at the same time.  The faq have examples for this but they all
> seem (needlessly) complicated to me.
> 
> The problem with the xsl as below is
> a) drops the first level of numbering (this happens as soon as
> you add the for-each loop.
> b) once properly ordered on the attribute, the numbering follows
> the document order and not the sorted order.
> 
> 
>       <!--START style content-->
>       <xsl:template match="body">
>         <xsl:for-each select="para[@order]">
>           <xsl:sort select="@order"/>
>             <xsl:apply-templates/>
>             </xsl:for-each>
>       </xsl:template>
> 
>       <xsl:template match="para">
>         <xsl:number level="multi" format="1."/>
>         <xsl:apply-templates/>
>       </xsl:template>
>       <!--END style content-->
> 
>   <!--START XML content-->
>   <body>
>     <para order="2">
>       C This is number 2
>       <para>
>         I am one in C
>       </para>
>       <para>
>         I am two in C
>       </para>
>     </para>
>     <para order="1">
>       B This is number 1
>       <para>
>         I am also one in B
>       </para>
>       <para>
>         I am two in B
>       </para>
>       <para>
>         I am three in B
>       </para>
>     </para>
>     <para order="3">
>       A This is number 3
>       <para>
>         I am three
>       </para>
>     </para>
>   </body>
>   <!--END XML content-->
> 
> 
> ===============
> As a final issue but not crucial issue, I would like to be able
> to have ordering and numbering for
>   <body>
>     <para order="2">
>       C This is number 2
>       <para>
>        <subpara>  
>          Some text
>         </subpara>
>        <subpara>  
>          Some text
>         </subpara>
> 
>     <para order="1">
>       C This is number 1
>       <para>
>        <subpara>  
>          Some text
>         </subpara>
>   </body>
> 
> -- 
> Eric Smith - currently using xalan and fop on linux
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.