You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Rick Bullotta <Ri...@lighthammer.com> on 2000/12/11 18:40:55 UTC

Bug/issue with default namespace & simple transform

We discovered this when prototyping XSLT-based processing of SDL files for a
SOAP server...

Using Xalan 1.2.2, given the following input:

<?xml version="1.0"?>
<A xmlns="urn:x.y.z">
	<B>
		<C>
			<D name="GetStockQuote"/>
		</C>
	</B>
</A>

and attempting to transform using the following XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" media-type="text/xml"/>

  <xsl:template match="/">
	<Items>
		<xsl:for-each select="/A/B/C/D">
			<Item><xsl:value-of select="@name"/></Item>
		</xsl:for-each>
	</Items>
  </xsl:template>
</xsl:stylesheet>


The output returns no matches.  We narrowed the issue down, by looking at
the Xalan code, to the nodeTest method of the SimpleNodeLocator class, for a
XPath.NODENAME test.  In this case, the target namespace is null, whereas
the context namespace is urn:x.y.z.  Thus, the match test fails.

Our question is:  Is this a bug or are we missing something on how to deal
with default namespaces?  Note that if we prefix the namespace declaration
in the input file, e.g. xmlns:soap="urn:x.y.z", it works fine).

Regards,

Rick Bullotta
VP/CTO
Lighthammer Software Development



Re: Bug/issue with default namespace & simple transform

Posted by Gary L Peskin <ga...@firstech.com>.
Rick Bullotta wrote:
> The output returns no matches.
> 
> Our question is:  Is this a bug or are we missing something on how to deal
> with default namespaces? 

The latter.  Each element in your input XML is treated as having a
namespace URI of urn:x.y.z because you have declared this as a default
namespace.

However, in your stylesheet, you are using unprefixed element names in
your select match pattern.

Section 2.3 of the XPath Recommendation
(http://www.w3.org/TR/xpath.html#node-tests) states:  "A QName in the
node test is expanded into an expanded-name using the namespace
declarations from the expression context. This is the same way expansion
is done for element type names in start and end-tags except that the
default namespace declared with xmlns is not used: if the QName does not
have a prefix, then the namespace URI is null (this is the same way
attribute names are expanded)."  Thus, unprefixed names in the
stylesheet, can only match elements in the input document for which the
namespace URI is null.

You can solve this problem by changing your stylesheet to:

  <xsl:for-each select="/foo:A/foo:B/foo:C/foo:D" xmlns:foo="urn:x.y.z">

HTH,
Gary