Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xsltproc vs XPath evaluate() method

From: "A. W. Dunstan" <no@----.------>
To: NULL
Date: 6/3/2008 2:46:00 PM

Martin Honnen wrote:

> A. W. Dunstan wrote:
> 
>>         DocumentBuilderFactory dbf =
>>         DocumentBuilderFactory.newInstance();
> 
> For XPath stuff you should always use a namespace aware factory/document
> builder so make sure you call the method to enable that.
> 
>> The XML source (src.xml, above) is:
>> 
>> <ns2:nuc2 xsi:schemaLocation="nuc2.xsd" xmlns:ns1="Exer_Sets"
>>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>    xmlns:ns2="nuc2">
>>    
>>   <ns1:Exer SetSequence="1" SetDescription="Exercise Identification">
>>     <ExerciseNickname>pushups</ExerciseNickname>
>>     <ExerciseAdditionalIdentifier>whatever</ExerciseAdditionalIdentifier>
>>   </ns1:Exer>
>> 
>> </ns2:nuc2>
> 
> So your XML uses namespaces, to cater for that the XSLT stylesheet needs
> to bind prefixes to the namespaces used:
>    <xsl:stylesheet
>      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>      version="1.0"
>      xmlns:ns2="nuc2"
>      xmlns:ns1="Exer_Sets"
>      exclude-result-prefixes="ns1 ns2">
> then you need to use those prefixes in your XPath expressions and in
> your XSLT match patterns:
> 
>     <xsl:value-of select="/ns2:nuc2/ns1:Exer/ExerciseNickname"/>
> 
> You just got lucky with your Java program as you used a not namespace
> aware DOM I think, if you use a namespace aware DOM then you need
> prefixes in your XPath expressions too and need to manage them in your
> Java program too.
 
It works!  Much thanks.  I'll go read up on namespaces.

-- 
Al Dunstan, Software Engineer
OptiMetrics, Inc.
3115 Professional Drive
Ann Arbor, MI  48104-5131


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