possible to sort 'java package' name with xslt

Discussion in 'XML' started by Petterson Mikael, Aug 29, 2005.

  1. Hi,

    I have the following package names ( in an xml) that I will transform to
    html. I need to sort them.

    <package name="se.company.product.subproduct.boam.fpx.testsignals">

    <package name="se.company.product.subproduct.boam.mao.iface.enum.hidden">

    When I use <xsl:sort select="." order="ascending"/>

    I cannot see any sorting being done.

    All advice is appreciated!

    cheers,

    //mikael
     
    Petterson Mikael, Aug 29, 2005
    #1
    1. Advertising

  2. Petterson Mikael wrote:

    > I have the following package names ( in an xml) that I will transform to
    > html. I need to sort them.
    >
    > <package name="se.company.product.subproduct.boam.fpx.testsignals">
    > <package name="se.company.product.subproduct.boam.mao.iface.enum.hidden">
    >
    > When I use <xsl:sort select="." order="ascending"/>
    >
    > I cannot see any sorting being done.


    Don't you want
    <xsl:sort select="@name"
    ?

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Aug 29, 2005
    #2
    1. Advertising

  3. Martin Honnen wrote:
    >
    >
    > Petterson Mikael wrote:
    >
    >> I have the following package names ( in an xml) that I will transform
    >> to html. I need to sort them.
    >>
    >> <package name="se.company.product.subproduct.boam.fpx.testsignals">
    >> <package name="se.company.product.subproduct.boam.mao.iface.enum.hidden">
    >>
    >> When I use <xsl:sort select="." order="ascending"/>
    >>
    >> I cannot see any sorting being done.

    >
    >
    > Don't you want
    > <xsl:sort select="@name"
    > ?
    >

    Hi,

    Well I still don't get any sorting done!

    I wonder if it is due to the dot in the package name. So the se is the
    only thing that will be sorted?

    cheers,

    //mikael
     
    Petterson Mikael, Aug 29, 2005
    #3
  4. Petterson Mikael wrote:


    > Well I still don't get any sorting done!


    Not sure what you are trying, with the example input being

    <?xml version="1.0" encoding="UTF-8"?>
    <package-list>
    <package name="se.company.product.subproduct.boam.fpx.testsignals" />
    <package
    name="se.company.product.subproduct.boam.mao.iface.enum.hidden" />
    </package-list>

    and an example stylesheet being

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:eek:utput method="xml" indent="yes" />

    <xsl:template match="package-list">
    <xsl:copy>
    <ascending>
    <xsl:apply-templates select="package">
    <xsl:sort select="@name" data-type="text" order="ascending" />
    </xsl:apply-templates>
    </ascending>
    <descending>
    <xsl:apply-templates select="package">
    <xsl:sort select="@name" data-type="text" order="descending" />
    </xsl:apply-templates>
    </descending>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="package">
    <xsl:copy>
    <xsl:copy-of select="@*" />
    </xsl:copy>
    </xsl:template>

    </xsl:stylesheet>

    the output is

    <?xml version="1.0" encoding="UTF-8"?>
    <package-list>
    <ascending>
    <package name="se.company.product.subproduct.boam.fpx.testsignals"/>
    <package
    name="se.company.product.subproduct.boam.mao.iface.enum.hidden"/>
    </ascending>
    <descending>
    <package
    name="se.company.product.subproduct.boam.mao.iface.enum.hidden"/>
    <package name="se.company.product.subproduct.boam.fpx.testsignals"/>
    </descending>
    </package-list>

    so sorting works.

    Of course it depends on the parts of the package names to have the same
    lengths so you might want to do
    <xsl:sort select="translate(@name, '.', '')"
    perhaps depending on what kind of names you want to sort.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Aug 29, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ted
    Replies:
    1
    Views:
    651
    Laurens
    Jan 26, 2004
  2. Replies:
    9
    Views:
    12,915
  3. George P
    Replies:
    3
    Views:
    707
    Alex Martelli
    Sep 11, 2004
  4. David Pratt
    Replies:
    4
    Views:
    348
    David Pratt
    May 13, 2006
  5. Navin
    Replies:
    1
    Views:
    761
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page