possible to sort 'java package' name with xslt

P

Petterson Mikael

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
 
M

Martin Honnen

Petterson said:
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"
?
 
P

Petterson Mikael

Martin said:
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
 
M

Martin Honnen

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How to sort a CSV file with merge sort JAVA 7
sort and numbering - xslt 7
Slow running XSLT: Any help appreciated 5
xslt help 3
XSL Sort 1
Merging tables with XSLT 2
Sort Before Paging 0
xslt sort options 1

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,251
Members
46,850
Latest member
Brightrs

Latest Threads

Top