Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Java 5/JAXP/ setParameter avoid conversion to string

Reply
Thread Tools

Java 5/JAXP/ setParameter avoid conversion to string

 
 
Piet71
Guest
Posts: n/a
 
      03-06-2007
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

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      03-07-2007
Piet71 wrote:
> 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
of them.

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
current context.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SetParameter in JS ignignokt Javascript 0 02-04-2007 12:18 AM
Avoid having a SQL express for web parts and avoid personalization Roger23 ASP .Net 2 10-12-2006 10:54 PM
setParameter for Applet ebramcity Java 6 07-17-2005 07:45 AM
Any way to avoid mass conversion of #INCLUDE files to UserControls? JJA ASP .Net Building Controls 13 07-27-2004 08:07 PM
Avoid wasting time or how to avoid initialization Alexander Malkis C++ 8 04-13-2004 11:23 PM



Advertisments