xsl-list
[Top] [All Lists]

Re: [xsl] XPath problem with namespace attribute

2008-09-05 11:59:35
Matthew Hailstone wrote:

It seems there is a bug in the XPath result when an empty namespace
attribute is used:

XML:
<?xml version="1.0" encoding="utf-8"?>
<One>
  <Two>
    <Three xmlns="http://www.hailstone.org/";>
      <Four>
          <Five/>
      </Four>
    </Three>
  </Two>
</One>

XPath:
/One/Two/Three/Four/Five

Expected Result:
The element "Five" should be returned.

Result:
Nothing is returned.

With XPath 1.0 'foo' selects elements with local name 'foo' in no namespace. As the elements 'Three', 'Four' and 'Five' are in the namespace http://www.hailstone.org/ you need to bind a prefix to that namespace URI and use that prefix in the XPath expresssion to qualify element names. How you bind a prefix to the namespace URI depends on the XPath API you use.
Within an XSLT stylesheet you can use
  <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:hs="http://www.hailstone.org/";
    version="1.0">
and then use e.g.
  /One/Two/hs:Three/hs:Four/hs:Five


--

        Martin Honnen
        http://JavaScript.FAQTs.com/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--