![]() |
|
|
|||||||
![]() |
XML - (Noob) Working with namespaces in XSLT |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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.) |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|