P
Piet71
Hi,
I have a stylesheet to select nodes from a source document via their
"position" attribute. The template snippet is as follows:
<xsl:template match="counter">
<xsl:if test="$number"><!--@pos=2 or @pos=5 or @pos=8 or @pos=11 or
@pos=13 or @pos=15-->
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>
$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
(Java 1.5).
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!
Best regards
Piet
I have a stylesheet to select nodes from a source document via their
"position" attribute. The template snippet is as follows:
<xsl:template match="counter">
<xsl:if test="$number"><!--@pos=2 or @pos=5 or @pos=8 or @pos=11 or
@pos=13 or @pos=15-->
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>
$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
(Java 1.5).
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!
Best regards
Piet