472,117 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,117 software developers and data experts.

possible to sort 'java package' name with xslt

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.tests ignals">

<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
Aug 29 '05 #1
3 1801


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.tests ignals">
<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/
Aug 29 '05 #2
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.tests ignals">
<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
Aug 29 '05 #3


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.tests ignals" />
<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:output 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.tests ignals"/>
<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.tests ignals"/>
</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/
Aug 29 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Lem | last post: by
reply views Thread by Ravi Tallury | last post: by
6 posts views Thread by Robbie Baldock | last post: by
1 post views Thread by aerotops | last post: by
10 posts views Thread by Jim Andersen | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.