[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XPath problem with namespace attribute


Subject: Re: [xsl] XPath problem with namespace attribute
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Fri, 05 Sep 2008 17:59:09 +0200

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/


Current Thread
Keywords