msxsl:node-set with default namespace

M

MoonStorm

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.
 
D

David Carlisle

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
 
C

Cody Amor

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?
 
D

David Carlisle

Cody Amor said:
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
 
C

Cody Amor

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

David Carlisle

Cody Amor said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top