[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: xpath if expression in Java

Subject: RE: xpath if expression in Java
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 5 Jan 2007 16:31:23 -0000
or expression in java
This is an XPath 2.0 expression, so you need to ensure you are using an
XPath 2.0 processor. You can achieve this by setting the system property
javax.xml.xpath.XPathFactory to net.sf.saxon.xpath.XPathFactoryImpl,
provided saxon8.jar and saxon8-xpath.jar are on your classpath.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: James Neff [mailto:jneff@xxxxxxxxxxxxxxxx] 
> Sent: 05 January 2007 16:01
> To: XSL list
> Subject:  xpath if expression in Java
> 
> Greetings,
> 
> My apologies if this is not the correct list to post this 
> question on.  
> I did look for an Xpath list specific to Java but could not find one.
> I have the following method in my Java application:
> 
> public String evaluateDocument(String inputDoc, String 
> xPathExpression){
> 
>        String results = "";
>                try{
>            XPathFactory factory = XPathFactory.newInstance();
>            XPath xPath = factory.newXPath();
>            InputSource inputSource = new InputSource(new 
> StringReader(inputDoc));
>            results = (String) xPath.evaluate(xPathExpression, 
> inputSource, XPathConstants.STRING);                      }
>          catch(Exception  e){
>            System.out.println("XpathHelper.evaluateDocument, 
> xPathExpression: " + xPathExpression + "  exception: " + e);  
>         }
>                  return results;
>            }
> 
> 
> The inputDoc is:
> 
> <enrollment_record>
>    <member_identifier>1234567890</member_identifier>
>    <subscriber_number>1234567890</subscriber_number>
> </enrollment_record>
> 
> 
> The XPath expression is:
> 
> if (enrollment_record/subscriber_number = 
> enrollment_record/member_identifier) then '1' else '2'
> 
> 
> If I run this XPath Expression from an XSLT stylesheet from 
> the command 
> line within a <xsl:value-of> element, I get the correct result.
> 
> 
> However, from within my java applicaiton I get:
> exception: javax.xml.xpath.XPathExpressionException
> 
> 
> It does not like the "if" statement within the XPath.  Other simple 
> XPath expressions do work.  It's as if the Java application 
> is using an 
> older parser that doesn't recognize the "if" statement.
> 
> How can I get my Java application to correctly process this XPath 
> expression?
> 
> Can someone point me in the right direction, or at least tell 
> me which 
> mailing list to post my question to?
> 
> Thank you in advance,
> James

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.