You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Stefano Mazzocchi <st...@apache.org> on 2000/08/24 20:31:41 UTC

XSLT and namespaces: two different planets

I got my hands dirty with SAX2 and, man, I love their namespace support,
it's great, clean, perfect, just fits perfectly with what I need.

Then I look at XSLT and, hmmm, their level of namespace support isn't
quite what I like... ok, let's make an example:

 <my:page xmlns:my="http://myhost.com/mystuff">
   ...
 </my:page>

How would a "normal" person access this in XSLT? simple

 <xsl:template match="my:page">
 </xsl:template>

All right (I know you already smell the problem, but keep going) then I
move my page to

 <my-stuff:page xmlns:my-stuff="http://myhost.com/mystuff">
  ...
 <my-stuff:page>

because I found that that the "my" prefix is used in another (and more
famous) schema.

Great, while good behaving SAX2 applications don't give a damn since the
"page" element is correctly interpreted (in memory) as

 http://myhost.com/mystuff^page

no matter what prefix is used (as the namespace spec rules), in XSLT...
well, I honestly don't know.

Please help, the XPath spec is not very clear about this.

-- 
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<st...@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------
 Missed us in Orlando? Make it up with ApacheCON Europe in London!
------------------------- http://ApacheCon.Com ---------------------


Re: XSLT and namespaces: two different planets

Posted by "Pier P. Fumagalli" <pi...@apache.org>.
Stefano Mazzocchi wrote:
> 
> I got my hands dirty with SAX2 and, man, I love their namespace support,
> it's great, clean, perfect, just fits perfectly with what I need.
> 
> Then I look at XSLT and, hmmm, their level of namespace support isn't
> quite what I like... ok, let's make an example:
> 
>  <my:page xmlns:my="http://myhost.com/mystuff">
>    ...
>  </my:page>
> 
> How would a "normal" person access this in XSLT? simple
> 
>  <xsl:template match="my:page">
>  </xsl:template>
> 
> All right (I know you already smell the problem, but keep going) then I
> move my page to
> 
>  <my-stuff:page xmlns:my-stuff="http://myhost.com/mystuff">
>   ...
>  <my-stuff:page>
> 
> because I found that that the "my" prefix is used in another (and more
> famous) schema.
> 
> Great, while good behaving SAX2 applications don't give a damn since the
> "page" element is correctly interpreted (in memory) as
> 
>  http://myhost.com/mystuff^page
> 
> no matter what prefix is used (as the namespace spec rules), in XSLT...
> well, I honestly don't know.
> 
> Please help, the XPath spec is not very clear about this.

Heh... Nice point... I really don't know since that's an XPATH
expression. I took a look at the <xsl:namespace-alias> but it seems that
this tag just converts the namespaces inside the stylesheet XML, not
inside the source XML...
I believe you have to change the prefix in the whole XSLT file, but, of
course, this sucks...

So, the question becomes, is there a way to associate a specific
namespace URI with a prefix into an XPATH expression???

	Pier

RE: XSLT and namespaces: two different planets

Posted by Conny Krappatsch <co...@smb-tec.com>.
I would agree with Ed,

I'm missing a very important part in Stefano's stylesheet example: the
namespace(ns) declaration. The stylesheet should look like this:

<xsl:stylesheet ...
    xmlns:my="http://myhost.com/mystuff">

    ...
    <xsl:template match="my:page">
    </xsl:template>
    ....
</xsl:stylesheet>

'my:page' will be expanded using the ns declaration (see Ed's mail).
The prefix can be seen as a link between the elements and the ns
declaration. You can even have several elements (and attributes) with different
prefixes belonging to the same ns (if you set your ns declarations
right).

Conny

Ed Staub wrote:
> Stefano,
> 
> I don't understand...
> 
> clearly you didn't really move the page, just changed the namespace prefix
> in this context.
> 
> Is the issue that the prefix in the stylesheet has to change if a matching
> _source_ prefix changes?  I don't believe this is true; namespaces are
> matched on the URI, not the prefix.  I haven't checked this to be positive
> that it's implemented correctly in Xalan, but I bet it is.  The XPath spec
> is pretty clear; in section 2.3: "A node test that is a QName is true if and
> only if the type of the node (see [5 Data Model]) is the principal node type
> and has an expanded-name equal to the expanded-name specified by the QName."
> ("Expanded name" is local part + URI.
> 
> Is the issue that the prefix in the stylesheet has to change if a matching
> destination prefix changes?  This can be dodged with <xsl:namespace-alias>,
> assuming it works correctly.
> 
> Or, in door #3... did I miss your point entirely?
> 
> -Ed Staub
> 
> -----Original Message-----
> From: Stefano Mazzocchi [mailto:stefano@apache.org]
> Sent: Thursday, August 24, 2000 2:32 PM
> To: Cocoon; Scott Boag
> Subject: XSLT and namespaces: two different planets
> 
> 
> I got my hands dirty with SAX2 and, man, I love their namespace support,
> it's great, clean, perfect, just fits perfectly with what I need.
> 
> Then I look at XSLT and, hmmm, their level of namespace support isn't
> quite what I like... ok, let's make an example:
> 
>  <my:page xmlns:my="http://myhost.com/mystuff">
>    ...
>  </my:page>
> 
> How would a "normal" person access this in XSLT? simple
> 
>  <xsl:template match="my:page">
>  </xsl:template>
> 
> All right (I know you already smell the problem, but keep going) then I
> move my page to
> 
>  <my-stuff:page xmlns:my-stuff="http://myhost.com/mystuff">
>   ...
>  <my-stuff:page>
> 
> because I found that that the "my" prefix is used in another (and more
> famous) schema.
> 
> Great, while good behaving SAX2 applications don't give a damn since the
> "page" element is correctly interpreted (in memory) as
> 
>  http://myhost.com/mystuff^page
> 
> no matter what prefix is used (as the namespace spec rules), in XSLT...
> well, I honestly don't know.
> 
> Please help, the XPath spec is not very clear about this.
> 
> --
> Stefano Mazzocchi      One must still have chaos in oneself to be
>                           able to give birth to a dancing star.
> <st...@apache.org>                             Friedrich Nietzsche
> --------------------------------------------------------------------
>  Missed us in Orlando? Make it up with ApacheCON Europe in London!
> ------------------------- http://ApacheCon.Com ---------------------
-- 
________________
Conny Krappatsch
SMB GmbH
mailto:conny@smb-tec.com
http://www.smb-tec.com


Re: XSLT and namespaces: two different planets

Posted by Stefano Mazzocchi <st...@apache.org>.
Ed Staub wrote:
> 
> Stefano,
> 
> I don't understand...
> 
> clearly you didn't really move the page, just changed the namespace prefix
> in this context.
> 
> Is the issue that the prefix in the stylesheet has to change if a matching
> _source_ prefix changes?  I don't believe this is true; namespaces are
> matched on the URI, not the prefix.  I haven't checked this to be positive
> that it's implemented correctly in Xalan, but I bet it is.  The XPath spec
> is pretty clear; in section 2.3: "A node test that is a QName is true if and
> only if the type of the node (see [5 Data Model]) is the principal node type
> and has an expanded-name equal to the expanded-name specified by the QName."
> ("Expanded name" is local part + URI.
> 
> Is the issue that the prefix in the stylesheet has to change if a matching
> destination prefix changes?  This can be dodged with <xsl:namespace-alias>,
> assuming it works correctly.
> 
> Or, in door #3... did I miss your point entirely?

No, no, it's me that I've been missing much of the namespace support in
XSLT, my fault.

You're right

 <xsl:template match="my:page">

works on the "real" name, not the prefix and uses the namespace
declaration that is available to that element to figure out what to do. 

I tried it in latest Xalan and it works.

Good, even better, I was afraid of our logicsheets been tight to a
particular prefix but I was wrong.

It feels good to be wrong when it saves you problems :)

Thanks to allo of you for your kind answers. I've read the XSLT spec 10
times now, but I think I have to read it again :)

-- 
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<st...@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------
 Missed us in Orlando? Make it up with ApacheCON Europe in London!
------------------------- http://ApacheCon.Com ---------------------



RE: XSLT and namespaces: two different planets

Posted by Ed Staub <es...@mediaone.net>.
Stefano,

I don't understand...

clearly you didn't really move the page, just changed the namespace prefix
in this context.

Is the issue that the prefix in the stylesheet has to change if a matching
_source_ prefix changes?  I don't believe this is true; namespaces are
matched on the URI, not the prefix.  I haven't checked this to be positive
that it's implemented correctly in Xalan, but I bet it is.  The XPath spec
is pretty clear; in section 2.3: "A node test that is a QName is true if and
only if the type of the node (see [5 Data Model]) is the principal node type
and has an expanded-name equal to the expanded-name specified by the QName."
("Expanded name" is local part + URI.

Is the issue that the prefix in the stylesheet has to change if a matching
destination prefix changes?  This can be dodged with <xsl:namespace-alias>,
assuming it works correctly.

Or, in door #3... did I miss your point entirely?

-Ed Staub

-----Original Message-----
From: Stefano Mazzocchi [mailto:stefano@apache.org]
Sent: Thursday, August 24, 2000 2:32 PM
To: Cocoon; Scott Boag
Subject: XSLT and namespaces: two different planets


I got my hands dirty with SAX2 and, man, I love their namespace support,
it's great, clean, perfect, just fits perfectly with what I need.

Then I look at XSLT and, hmmm, their level of namespace support isn't
quite what I like... ok, let's make an example:

 <my:page xmlns:my="http://myhost.com/mystuff">
   ...
 </my:page>

How would a "normal" person access this in XSLT? simple

 <xsl:template match="my:page">
 </xsl:template>

All right (I know you already smell the problem, but keep going) then I
move my page to

 <my-stuff:page xmlns:my-stuff="http://myhost.com/mystuff">
  ...
 <my-stuff:page>

because I found that that the "my" prefix is used in another (and more
famous) schema.

Great, while good behaving SAX2 applications don't give a damn since the
"page" element is correctly interpreted (in memory) as

 http://myhost.com/mystuff^page

no matter what prefix is used (as the namespace spec rules), in XSLT...
well, I honestly don't know.

Please help, the XPath spec is not very clear about this.

--
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<st...@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------
 Missed us in Orlando? Make it up with ApacheCON Europe in London!
------------------------- http://ApacheCon.Com ---------------------