Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: xsltproc vs XPath evaluate() method [Thread Next] Re: xsltproc vs XPath evaluate() methodTo: 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 | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
