Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Sorting and replacing content

From: "Andrew Welch" <ajwelch@--------------->
To:
Date: 9/1/2004 9:44:00 AM
> I have this structure where the content of tags <A> to <E>
> have to determine the order of tag-content <a> to <e>. The
> result needs to be as shown below.
>
> I can manage to make a stylesheet with an <xsl:if> for each
> <A> to <E> asking whether the number is 1, 2, 3, 4 or 5, but
> I am sure there must be a simpler way to do this. I can not
> use position() since the position af the tags can change in
> the structure.
>
> <Root>
> <a>10</a>
> <b>20</b>
> <c>30</c>
> <d>40</d>
> <e>50</e>
> ...
>
> ...
> <A>3</A>
> <B>5</B>
> <C>1</C>
> <D>2</D>
> <E>4</E>
> </Root>
>
> Result I need:
>
> <no>30</no> <!-- C = 1 has to be first with the value of c
> (which is 30) --> <no>40</no> <no>10</no> <no>50</no> <no>30</no>


How about:

<xsl:variable name="uppercase" select="'ABCDE'"/>
<xsl:variable name="lowercase" select="'abcde'"/>

<xsl:template match="Root">
  <xsl:apply-templates select="A|B|C|D|E">
    <xsl:sort select="." data-type="number"/>
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="A|B|C|D|E">
  <xsl:apply-templates select="/Root/*[local-name() =
translate(local-name(current()), $uppercase, $lowercase)]"/>
</xsl:template>

<xsl:template match="a|b|c|d|e">
  <no><xsl:value-of select="."/></no>
</xsl:template>

This sorts the uppercase elements and then calls apply-templates for the
lowercase namesakes.  It produces this output:

<no>30</no><no>40</no><no>10</no><no>50</no><no>20</no>

The last <no> is different to your example output, but I'm guessing
that's a typo.

cheers
andrew


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