Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] xpath if expression in Java

From: "Michael Kay" <mike@------------>
To:
Date: 1/5/2007 4:32:00 PM
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: [xsl] 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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent