You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bu...@apache.org on 2013/06/28 19:32:13 UTC

[Bug 21525] XSLT/param@expression used as string instead of as expression as documented

https://issues.apache.org/bugzilla/show_bug.cgi?id=21525

František Kučera <xkucf03/> <is...@frantovo.cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |issues.apache.org.db7c0rhii
                   |                            |@frantovo.cz
         Resolution|FIXED                       |---

--- Comment #4 from František Kučera <xkucf03/> <is...@frantovo.cz> ---
After almost ten years it is time to reopen this bug.

Parameters in XSLT can be of many data types, they can be booleans, numbers,
nodes etc. not only strings.

Current version of Ant supports only strings. And it is problem if you need
e.g. boolean to be evaluated in XSLT IF/WHEN.
In such case you have to do a workaround in XSTL template like manual casting
from string to boolean (which means that you have two different names from one
parameter – different in Ant and different in XSLT)
or doing test="$param = 'true'" instead of just test="$param".
Other option is using an XSLT processor which does the some automatic/magic
casting for you
e.g. SaxonB 9.0 – but this magic stopped working in 9.1 (the magic behaviour is
not based on the specification).

So here is a patch that adds support for several data types. Now you can write
for example:

<param name="p6" expression="true" type="boolean"/>
<param name="p6" expression="128" type="int"/>
<param name="p6" expression="some text"/>

(default type is string to be compatible with current build.xml files)

And in XSL template you will get a property with appropriate data type.

These types are supported
    string
    boolean
    int
    long
    double
(more can be easily added if needed).

And also XPath expressions are supported – types:
    xpath:string
    xpath:boolean
    xpath:number
    xpath:node
    xpath:nodeset

So you can write e.g.:

<param name="p3" expression="64 * 64 div 128 + 10" type="xpath:number"/>

And in XSLT you will get numeric parameter with value 42.

For more examples please see attached files.

The XPath expression is evaluated on empty document, not on the transformed
document, because it is not available yet.
Despite that you can compute something useful, call standard XPath functions
and also access declared properties from Ant build.xml file.

n.b. if you use ${someParam} in the expression attribute it will by simply
substituted by Ant,
but if you use $someParam here, the value will be evaluated by XPath processor.

I hope this patch will be useful for other users.

-- 
You are receiving this mail because:
You are the assignee for the bug.