Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - (Noob) Working with namespaces in XSLT

 
Thread Tools Search this Thread
Old 05-23-2006, 04:37 PM   #1
Default (Noob) Working with namespaces in XSLT


Hi All

I am re-visiting XSLT after not touching it for about three years, so
to be honest I am starting myself from scratch.

If I have XML under the namespace "http://tempuri.com/abc/2002/09",
should I declare this at the top of my XSLT?

Additionally, if I have the following XML:

<myxmlroot xmlns="http://tempuri.com/abc/2002/09">
<header somevalue="" anotherval="" />
<mainbody>
<repeateditem id="0">Zero</repeateditem>
<repeateditem id="1">One</repeateditem>
<repeateditem id="2">Two</repeateditem>
</mainbody>
</myxmlroot>

Where am I going wrong in my XSLT?

<xsl:for-each select="/myxmlroot/mainbody">
Loop<br />
</xsl:for-each>

That doesn't seem to give me any output - hence my question about the
namespace.

Many thanks

Darren



daz_oldham
  Reply With Quote
Old 05-23-2006, 04:53 PM   #2
Joe Kesselman
 
Posts: n/a
Default Re: (Noob) Working with namespaces in XSLT

daz_oldham wrote:
> If I have XML under the namespace "http://tempuri.com/abc/2002/09",
> should I declare this at the top of my XSLT?


Yes. Bind it to a prefix. Then use that prefix in your XPaths, even if
you used the xmlns= shorthand in your documents; XSLT has no concept of
default namespace, so all references to namespaced elements and
attributes must use prefixed names.

<xsl:for-each select="/myns:myxmlroot/myns:mainbody"
xmlns:myns="http://tempuri.com/abc/2002/09">
Loop<br />
</xsl:for-each>

(In most cases you'd declare the prefix at the top of the stylesheet;
I'm doing it here just for illustrative purposes.)
  Reply With Quote
Old 05-23-2006, 05:06 PM   #3
daz_oldham
 
Posts: n/a
Default Re: (Noob) Working with namespaces in XSLT

Thanks Joe

I have that working now

Well, I do have futher problems, but I'll have a proper bash at them
before I post again!

Daz

  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump