Re: xsltproc vs XPath evaluate() method

Discussion in 'XML' started by Martin Honnen, Jun 3, 2008.

  1. 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/
    Martin Honnen, Jun 3, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Son KwonNam
    Replies:
    4
    Views:
    7,027
    Joris Gillis
    Jan 5, 2005
  2. Loudin
    Replies:
    1
    Views:
    760
    David Carlisle
    Jul 1, 2005
  3. Replies:
    9
    Views:
    1,434
  4. Arndt Jonasson

    text() in XPath limited in xsltproc?

    Arndt Jonasson, Aug 8, 2007, in forum: XML
    Replies:
    1
    Views:
    1,668
    Pavel Lepin
    Aug 8, 2007
  5. Jack Frillman
    Replies:
    2
    Views:
    2,687
    Martin Honnen
    Mar 17, 2011
Loading...

Share This Page