(Noob) Working with namespaces in XSLT

Discussion in 'XML' started by daz_oldham, May 23, 2006.

  1. daz_oldham

    daz_oldham Guest

    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, May 23, 2006
    #1
    1. Advertising

  2. 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.)
    Joe Kesselman, May 23, 2006
    #2
    1. Advertising

  3. daz_oldham

    daz_oldham Guest

    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
    daz_oldham, May 23, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Fox

    XML & XSLT namespaces

    Colin Fox, Jan 11, 2004, in forum: XML
    Replies:
    2
    Views:
    446
    Colin Fox
    Jan 11, 2004
  2. Thomas Wittek

    XSLT: Normalizing namespaces

    Thomas Wittek, Aug 30, 2007, in forum: XML
    Replies:
    5
    Views:
    1,175
    Martin Honnen
    Aug 31, 2007
  3. Andy Fish

    namespaces in XSLT

    Andy Fish, Feb 29, 2008, in forum: XML
    Replies:
    3
    Views:
    522
    Joseph Kesselman
    Feb 29, 2008
  4. TripleJay

    XSLT Noob with a problem

    TripleJay, Jul 3, 2010, in forum: XML
    Replies:
    5
    Views:
    1,942
    Peter Flynn
    Jul 5, 2010
  5. S2

    xslt and namespaces

    S2, Nov 5, 2010, in forum: XML
    Replies:
    2
    Views:
    1,456
Loading...

Share This Page