Java 5/JAXP/ setParameter avoid conversion to string
I have a stylesheet to select nodes from a source document via their
"position" attribute. The template snippet is as follows:
<xsl:if test="$number"><!--@pos=2 or @pos=5 or @pos=8 or @pos=11 or
@pos=13 or @pos=15-->
$number is a parameter supplied by the user. An example is given in
the commented section. This is running nicely from the command line
with Xalan 2.7.
However when I try to set this parameter from within my Java code
Transformer tf = TransformerFactory.newInstance().newTransformer();
tf.setParameter("number","@pos=1 or @pos=2");
apparently what is supposed to be an XPath expression is treated as a
simple string which is non-empty and thus evaluated in a boolean
context as true. Consequently, instead of getting just the counters
with the appropriate positions, I get all counters back!
I had a brief look in the source code of
org.apache.xalan.xslt.Process.java which is the class that does the
transformation from the command line, and their as well all parameters
are treated as Strings (they are even explictly casted).
So my question is why are the two ways giving different results? How
can I avoid that "@pos=1 or @pos=2" is transformed from an expression
to a simple string? Is their a special property that I have to set?
Many thanks for your help!
Re: Java 5/JAXP/ setParameter avoid conversion to string
> How can I avoid that "@pos=1 or @pos=2" is transformed from an expression
> to a simple string?
In general you can't.
In *SOME* cases, you can use an Attribute Value Template to have an
expression evaluated to produce the value for an attribute (see the XSLT
spec for a discussion of how that works), but I suspect this isn't one
Some XSLT processors -- not all by a long shot -- support an extension
function which can take an expression as a string and evaluate it in the
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
|All times are GMT. The time now is 05:21 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.