Re: [xsl] XPath - accessing nodes with a namespace with no prefix

Subject: Re: [xsl] XPath - accessing nodes with a namespace with no prefix
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Sat, 5 Dec 2009 12:50:41 +0530
On Sat, Dec 5, 2009 at 4:51 AM, Philip Vallone
<philip.vallone@xxxxxxxxxxx> wrote:
> (3) It's possible to select a node by using local-name() in a predicate with a wild card e.g. //*[local-name()='title']. however, this may give me the wrong result. I wasn't sure if there was another way

With XSLT 1.0, I would do this something like following:

<xsl:stylesheet xmlns:xsl="";

<xsl:variable name="titleVal"
select="/xx:organizations/xx:organization/xx:item[2]/xx:title" />
<xsl:value-of select="$titleVal" />

With, XSLT 2.0 I might prefer (this solution won't need the namespace
declaration for, XML namespace
on xsl:stylesheet instruction):

<xsl:variable name="titleVal" select="/organizations/organization/item[2]/title"
	           xpath-default-namespace=""; />
<xsl:value-of select="$titleVal" />

Such a facility in XSLT 2.0 allows us to have the
xpath-default-namespace, syntax local to any XSLT 2 instruction,
making the stylesheet design more flexible.

The attribute, xpath-default-namespace can also be global to the
stylesheet (i.e, present on xsl:stylesheet instruction, where it get's
available to the whole of stylesheet).

Just also to mention, xpath-default-namespace can be specified in an
inheritable fashion within the stylesheet, where the descendant XSLT 2
instructions can override, the xpath-default-namespace value present
on the ancestor element.

Mukul Gandhi

Current Thread