Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Unsorted position in for-each [Thread Next] Re: Unsorted position in for-eachTo: 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/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
