Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Unsorted position in for-each

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 5/6/2008 4:52:00 PM

Sean Keesler wrote:

> I will sort the "foo's" and I want to create the following:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <newRoot>
>     <foo name="A" sortedPosition="1" originalPosition="4"/>
>     <foo name="B" sortedPosition="2" originalPosition="3"/>
>     <foo name="C" sortedPosition="3" originalPosition="2"/>
>     <foo name="D" sortedPosition="4" originalPosition="1"/>
> </newRoot>
> 
> How do I get the "originalPosition"?

xsl:number should help:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

   <xsl:output method="xml" indent="yes"/>

   <xsl:template match="bar">
     <newRoot>
       <xsl:apply-templates select="foo">
         <xsl:sort select="." data-type="text"/>
       </xsl:apply-templates>
     </newRoot>
   </xsl:template>

   <xsl:template match="foo">
     <xsl:copy>
       <xsl:attribute name="name">
         <xsl:value-of select="."/>
       </xsl:attribute>
       <xsl:attribute name="sortedPosition">
         <xsl:value-of select="position()"/>
       </xsl:attribute>
       <xsl:attribute name="originalPosition">
         <xsl:number/>
       </xsl:attribute>
     </xsl:copy>
   </xsl:template>

</xsl:stylesheet>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent