Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > (Noob) Working with namespaces in XSLT

Reply
Thread Tools

(Noob) Working with namespaces in XSLT

 
 
daz_oldham
Guest
Posts: n/a
 
      05-23-2006
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

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      05-23-2006
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
 
 
 
 
daz_oldham
Guest
Posts: n/a
 
      05-23-2006
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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt and namespaces S2 XML 2 11-08-2010 08:25 AM
namespaces in XSLT Andy Fish XML 3 02-29-2008 02:05 PM
XSLT: Normalizing namespaces Thomas Wittek XML 5 08-31-2007 12:16 PM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM
XML & XSLT namespaces Colin Fox XML 2 01-11-2004 05:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57