473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Java 5/JAXP/ setParameter avoid conversion to string

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

Mar 6 '07 #1
1 1764
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
Mar 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
0
by: Brian | last post by:
I am having alot of trouble getting a XML document validated with a schema. I got a sample document and schema off of w3schools.com, which passed an online xml validator:...
1
by: Carlitos | last post by:
Hi there, I'm a beginner on XML. At this moment I am working on a conversion to C# of a (pretty large) program originally coded in Java. It's not much what the JLCA does when converting XML...
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
1
by: Simon Brooke | last post by:
Yet another silly question, but this just might be the crucial one. In answer to another of my silly questions, Björn Höhrmann pointed me to http://home.ccil.org/~cowan/XML/tagsoup/, and as I...
1
by: jaimemartin | last post by:
hello, I want to validate an xml by means of a schema (xsd). To do that first of all I´m using a SchemaFactory. The problem is that if I run the code in Windows all works fine, but If I run it in...
7
by: svpriyan | last post by:
Dear Buddies, I have two Java Prog: My task is to read the Content of the file and write to an XML file. so i started doing it perfectly... What i have problem is when i tried to execute the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.