[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XPath - accessing nodes with a namespace with no

Subject: Re: XPath - accessing nodes with a namespace with no prefix
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Sat, 5 Dec 2009 12:50:41 +0530
Re:  XPath - accessing nodes with a namespace with no
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="http://www.w3.org/1999/XSL/Transform"
                        xmlns:xx="http://www.imsglobal.org/xsd/imscp_v1p1"
		        version="2.0">

<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 http://www.imsglobal.org/xsd/imscp_v1p1
on xsl:stylesheet instruction):

<xsl:variable name="titleVal" select="/organizations/organization/item[2]/title"
	           xpath-default-namespace="http://www.imsglobal.org/xsd/imscp_v1p1" />
<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.



-- 
Regards,
Mukul Gandhi

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.