Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - xsltproc vs XPath evaluate() method >Thread Next - Re: xsltproc vs XPath evaluate() method Re: xsltproc vs XPath evaluate() methodTo: NULL Date: 6/3/2008 6:50:00 PM 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. -- Martin Honnen http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
