msxsl:node-set with default namespace

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MoonStorm

    msxsl:node-set with default namespace

    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="layoutSet tings">
    <module>
    <size>345</size>
    <title>whatever </title>
    </module>
    </xsl:variable>

    My standard namespaces look like this:
    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="ur n: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:n ode-set($moduleSett ings)/module/size" will return
    nothing.

  • David Carlisle

    #2
    Re: msxsl:node-set with default namespace


    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

    Comment

    • Cody Amor

      #3
      Re: msxsl:node-set with default namespace


      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!

      Comment

      • David Carlisle

        #4
        Re: msxsl:node-set with default namespace

        Cody Amor <moonstorm@gmai l.com> writes:
        [color=blue]
        > 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?
        >[/color]

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

        <xsl:styleshe et 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

        Comment

        • Cody Amor

          #5
          Re: msxsl:node-set with default namespace

          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!

          Comment

          • David Carlisle

            #6
            Re: msxsl:node-set with default namespace

            Cody Amor <moonstorm@gmai l.com> writes:
            [color=blue]
            > Brrrrr, yes, it works. Thanks a lot.
            > Hopefully the standard will evolve in a more friendly way.[/color]

            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.



            David

            Comment

            Working...