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

Namespaces in XSL and how to access the elements

Subject: Namespaces in XSL and how to access the elements
From: "Rob Sutherland" <rob@xxxxxxxxxxxxxxxxx>
Date: Wed, 26 Feb 2003 15:23:49 -0800
rob sutherland
Hello all:


I am trying to get my brain around Namespaces in XSL.

I think the example below will make clear what i am struggling with.


XML file
<<<

<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

...

<item rdf:about="url-here">
<title>Title would go here</title>
...
</item>

...

</rdf:RDF>
>>>


I want to get to the <item> elements whose parent is the <rdf:RDF> element.
I can get to the <rdf:RDF> element by using the following.

<xsl:stylesheet version="1.0"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	exclude-result-prefixes="rdf" >

<xsl:template match="rdf:RDF">

Now, what i thought would work to select the <item> elements now that I am
in the proper context would be the following.

	<xsl:for-each select="item">
		<xsl:value-of select="title" /><br />
	</xsl:for-each>

But this doesn't work. I get no output.

So I went about it another way and came up with this:

	<xsl:for-each select="./*[name(.) = 'item']">
		<xsl:value-of select="./*[name(.) = 'title']" /><br />
	</xsl:for-each>

Now this works, but seems cumbersome and not as effecient/quick as it could
be.

So i have something that works, but i want to know if there is a better/more
correct way to do this. If not okay, then i have what i am looking for, but
i just wanted some advice from somebody with more XSL experience.


Rob Sutherland


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.