ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Al Le" <>
Subject XSL transformation with Ant: sorting a list
Date Mon, 07 Mar 2016 06:37:14 GMT

I'm facing a weird problem (IMHO) which, in short, is:

a node list passed as a parameter to a template can't be sorted.

The problem occurs only if I do the transformation from within Ant (I use Ant 1.8.4). It does
not occur if I perform it via a Java program or in XmlSpy or through

Here's an example.

The input file (a.xml) is:


The transformation (trans.xml) is:

<xsl:stylesheet version="1.0" 

  <xsl:output method="xml" />

  <xsl:template match="/">
      <xsl:call-template name="processThis">
        <xsl:with-param name="nodeList" select="/*/a"/>

  <xsl:template name="processThis">
    <xsl:param name="nodeList" />

      <xsl:for-each select="$nodeList">
        <xsl:sort /><!-- ***** This causes the problem -->
        <xsl:variable name="thisVal" select="." />
        <result value="{$thisVal}" />


The Ant script is:

<project default="trans">
    <target name="trans">
        <delete file="out.xml"/>
        <xslt style="trans.xsl" in="a.xml" out="out.xml"/>

The expected output is:

    <result value="AAA" />
    <result value="BBB" />

But if I run the ant script, just an empty 'Root' element is generated, without child nodes.

If I comment out the line marked with '*****', the generated Root element does contain child
elements, but unsorted (as one would expect in this case).

If I process the elements directly (and not in a template passing the list to process as a
parameter), then I can use 'sort', and everything works as expected. Here is the 'direct'

<xsl:stylesheet version="1.0" xmlns:xsl="">

    <xsl:output method="xml" />

    <xsl:template match="/">
            <xsl:for-each select="/*/a">
                <xsl:sort />
                <xsl:variable name="thisVal" select="." />
                <result value="{$thisVal}" />


So my question is: why isn't a list passed as a parameter to a template processed with a 'sort'
option -- in Ant?

Thank you!

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message