xsl-list
[Top] [All Lists]

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

2009-12-04 17:42:46
Hi Ken,

Thank you for your help. I should have been more clear. I am not using XSLT, 
but rather libxml2 for C.

What I ended up doing was to give the namespace a prefix, but was wondering if 
there was another way.

xmlns:n="http://www.imsglobal.org/xsd/imscp_v1p1";

Thanks for your help,

Phil

On Dec 4, 2009, at 5:17 PM, G. Ken Holman wrote:

At 2009-12-04 17:04 -0500, Philip Vallone wrote:
This is a pure xpath question.

Which is frequently asked.

Suppose I have a namespace declaration like this:

<organizations version="1.0" xmlns="http://www.imsglobal.org/xsd/imscp_v1p1";>

The namespace does not have a prefix.

Right, but the element node in the tree has the namespace in the expanded 
name.

I want to use local-name() to access the nodes

Why?  That would be improper.  You want to use qualified names representing 
expanded names to access the node.

but not sure how. For example, how do I access a path like this:

XPATH:

/organizations/organization/title[2]/title

In an XSLT 1 or XSLT 2 stylesheet:

xmlns:ims="http://www.imsglobal.org/xsd/imscp_v1p1";
...
/ims:organizations/ims:organization/ims:title[2]/ims:title

XML:
       <organizations version="1.0" 
xmlns="http://www.imsglobal.org/xsd/imscp_v1p1";>
               <organization>
                       <title>SCORM 2004 4th Edition Manifest Basics Content 
Example 1.0</title>
...

The expanded name in the stylesheet must match the expanded name in the XML 
data.  The qualified name in the stylesheet can be different than the 
qualified name in the XML data.  The qualified name in the stylesheet cannot 
use the default namespace in XSLT 1.

In XSLT 2 you can use xpath-default-namespace= to support unprefixed names in 
XPath, but I've come to the conclusion it isn't helpful when more than one 
input namespace is in use.

I hope this helps.

. . . . . . . . . . . Ken

--
XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--