msxsl:node-set with default namespace

Discussion in 'XML' started by MoonStorm, Mar 7, 2005.

  1. MoonStorm

    MoonStorm Guest

    Hi guys,

    Please solve a puzzle I am trying to figure out for some time.
    Let's say I have a fragment stored inside a variable, for instance:

    <xsl:variable name="layoutSettings">
    <module>
    <size>345</size>
    <title>whatever</title>
    </module>
    </xsl:variable>

    My standard namespaces look like this:
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt">

    The node-set function behaves as expected.
    The trouble appears when I try to add a default namespace to the
    xsl:stylesheet declaration. A
    select="msxsl:node-set($moduleSettings)/module/size" will return
    nothing.
    MoonStorm, Mar 7, 2005
    #1
    1. Advertising

  2. The node-set function behaves as expected.
    The trouble appears when I try to add a default namespace to the
    xsl:stylesheet declaration. A

    This behaviour is nothing to do with node-set() you will see the same
    behaviour if you add a namespace to a source document. unprefixed
    element names in XPath 1 _always_ refer to elements in no-namespace.

    By adding a default namespace the elements in your variable are now in
    that namespace.

    Either you have to prefix the names in the Xpath or add xmlns="" to the
    xsl:variable so the elements within it are in no-namespace.

    David
    David Carlisle, Mar 7, 2005
    #2
    1. Advertising

  3. MoonStorm

    Cody Amor Guest

    Yes, you are right. Now it works.

    However, from what I understand and tested, I cannot prefix the names in
    xpath with the default namespace. If I choose this option, I have to
    declare a new namespace and include the elements in that namespace. Am I
    right?

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Cody Amor, Mar 8, 2005
    #3
  4. Cody Amor <> writes:

    > Yes, you are right. Now it works.
    >
    > However, from what I understand and tested, I cannot prefix the names in
    > xpath with the default namespace. If I choose this option, I have to
    > declare a new namespace and include the elements in that namespace. Am I
    > right?
    >


    you need to declare the same namespace twice with and without a prefix

    <xsl:stylesheet xmlns="wibble" xmlns="w:wibble" ....

    Now a literal result element of
    <foo> is foo in wibble namepsace (as is <w:foo> ) and an Xpath of
    //x:foo will find foo in the wibble namespace (whether or not it was
    prefixed in the source)

    David
    David Carlisle, Mar 8, 2005
    #4
  5. MoonStorm

    Cody Amor Guest

    Brrrrr, yes, it works. Thanks a lot.
    Hopefully the standard will evolve in a more friendly way.


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Cody Amor, Mar 8, 2005
    #5
  6. Cody Amor <> writes:

    > Brrrrr, yes, it works. Thanks a lot.
    > Hopefully the standard will evolve in a more friendly way.


    Yes it will, XSLT2 draft (which is already implemented in, eg, saxon8.x)
    allows you to specify a default namespace for element names in Xpath
    expressions, so you could keep everything unprefixed, and just use the
    default namespace, then also declare that unprefixed xpath names refer
    to that.

    http://www.w3.org/TR/xslt20/#unprefixed-qnames

    David
    David Carlisle, Mar 8, 2005
    #6
    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. Replies:
    0
    Views:
    1,399
  2. ipg
    Replies:
    5
    Views:
    2,055
    Oleg Tkachenko
    Aug 27, 2003
  3. Patrick Gresham
    Replies:
    2
    Views:
    926
    Dimitre Novatchev
    Aug 21, 2003
  4. MoonStorm
    Replies:
    0
    Views:
    423
    MoonStorm
    Mar 7, 2005
  5. Tjerk Wolterink
    Replies:
    2
    Views:
    1,399
    Dimitre Novatchev
    Aug 24, 2006
Loading...

Share This Page