Yes, and both are conformant with the specification.
The way this is formally described in the XSLT 1.0 specification is that
generation of namespace declarations is done by the serializer. (This
changes in XSLT 2.0, the generation is now done by a process called
"namespace fixup" as soon as an element is created on the result tree.
This makes a difference in 2.0, because result trees can be used as the
input to further processing, but the difference is invisible in XSLT
1.0).
Technically, the result tree contains the element named
{http://www.icpsr.umich.edu/DDI}docDscr. The element node does not have
any information about a prefix. There is no namespace node for this
namespace attached to the element, because it was suppressed by the
exclude-result-prefixes declaration. The serializer has to ensure that
there is a namespace declaration for this namespace in the serialized
output; it has to invent a prefix, use it in producing the element name,
and declare it. It is allowed to do this any way it likes, and Saxon and
Xalan are doing it differently.
Note that the description of exclude-result-prefix says that it is a
request to make the corresponding namespace [URI] an excluded namespace;
it prevents all namespace declarations using this URI from being copied
to the result tree, not just the one with the specified prefix. Saxon is
using the rule "I know this namespace URI is needed in the result tree,
therefore I am going to ignore the request to exclude it", and it
actually copies all the namespace nodes for this URI over. The main
reason for this is that it makes it easy to reuse a familiar prefix
rather than inventing an arbitrary one (which would also be permitted).
Xalan, it appears, is excluding all the namespace nodes and then putting
one of them back again, while still remembering the original prefix that
was used. You could argue that in this case this is smarter, but it goes
beyond what the spec demands, and both are conformant.
Michael Kay
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
Mark R. Diggory
Sent: 22 August 2003 21:11
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: AW: [xsl] exclude result prefixes doesn't stop
prefix from showingup.
After testing it appears that Xalan behaves differently than Saxon on
the following stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:ddi="http://www.icpsr.umich.edu/DDI"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="ddi"
>
<xsl:template match="@* | *">
<xsl:copy>
<xsl:apply-templates select="* | @* | text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ddi:codeBook">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<docDscr xmlns="http://www.icpsr.umich.edu/DDI">
<citation>
<titlStmt>
<titl>
<xsl:value-of
select="ddi:stdyDscr/ddi:citation/ddi:titlStmt/ddi:titl"/>
</titl>
</titlStmt>
</citation>
</docDscr>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Xalan effectively suppresses the excess
xmlns:ddi="http://www.icpsr.umich.edu/DDI" namespace in the result
document while Saxon does not. This would appear to be a issue with
Saxon and exclude-result-prefixes.
-Mark
Mark R. Diggory wrote:
Yes, this is what I thought as well. But exclude-result-prefixes
doesn't
accomplish this with my current config.
I'm going to switch over to Xalan and test it there to see if Saxon
and
Xalan behave differently in respect to this case.
-Mark
Michael Kay wrote:
Thanks for the idea, but it didn't change the behavior, the result
still looks like this:
<?xml version="1.0" encoding="utf-8"?>
<codeBook xmlns="http://www.icpsr.umich.edu/DDI">
<docDscr xmlns:ddi="http://www.icpsr.umich.edu/DDI">
<citation>
<titlStmt>...
Now you do have a namespace declaration in the result which is not
being used, and is only there because it was in scope for
the literal
result element that created it. This *is* the situation where
exclude-result-prefixes works.
Michael Kay
Markus Abt wrote:
Mark,
try to put the namespace node at the root element of the result,
not at xsl:stylesheet:
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet
version="1.0"
xmlns:ddi="http://www.icpsr.umich.edu/DDI"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="ddi:codeBook">
<xsl:copy xmlns="http://www.icpsr.umich.edu/DDI">
<xsl:apply-templates select="@*"/>
<docDscr>
<citation>
<titlStmt>
<titl>
<xsl:value-of
select="ddi:stdyDscr/ddi:citation/ddi:titlStmt/ddi:titl"/>
</titl>
</titlStmt>
</citation>
</docDscr>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Regards,
Markus
__________________________
Markus Abt
Comet Computer GmbH
http://www.comet.de
----------
Von: Mark R. Diggory
Gesendet: Freitag, 22. August 2003 17:33
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Betreff: Re: [xsl] exclude result prefixes doesn't stop
prefix from showingup.
I did see that particular Q/A in the XSL FAQ and in your
book, I agree
it works, but I feel like its a bit of an overkill
Initially I had tried to write the stylesheet using the DDI
namespace
as
the default namespace, like below. but this failed to
detect the default
namespace in the source document so none of the source
elements were
properly matched. I thought to myself, there should be some
way I can
match the default namespace in the source document? But I
can't find
anything that does this. I came across the #default entity,
but this
doesn't seem to fit either.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns="http://www.icpsr.umich.edu/DDI"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="ddi"
>
<xsl:template match="codeBook">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<docDscr>
...
<titl>
<xsl:value-of
select="stdyDscr/citation/titlStmt/titl"/>
</titl>
...
</docDscr>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:template>
...
</xsl:stylesheet>
Michael Kay wrote:
exclude-result-prefixes only affects the namespaces copied from
the
stylesheet by a literal result element, it doesn't affect
copying of
namespaces from source documents. In any case, the codeBook
element is
in the namespace http://www.icpsr.umich.edu/DDI, so the
namespace must
be declared. exclude-result-prefixes only suppresses
namespaces that
are not used in any element or attribute name, and this
namespace is
used. What you want to do is not to suppress the namespace
declaration, it is to change the name of the element, which
you can do
by using <xsl:element name="{local-name(.)}"> in place of
xsl:copy.
Michael Kay
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On
Behalf Of Mark
R. Diggory
Sent: 21 August 2003 23:10
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] exclude result prefixes doesn't stop prefix
from showing up.
I have a stylesheet that copies an xml document with a default
namespace while it also is adding some content to it:
*The stylesheet*
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns="http://www.icpsr.umich.edu/DDI"
xmlns:ddi="http://www.icpsr.umich.edu/DDI"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="ddi"
>
<xsl:template match="@* | *">
<xsl:copy>
<xsl:apply-templates select="* | @* | text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ddi:codeBook">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<docDscr>
<citation>
<titlStmt>
<titl>
<xsl:value-of
select="ddi:stdyDscr/ddi:citation/ddi:titlStmt/ddi:titl"/>
</titl>
</titlStmt>
</citation>
</docDscr>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
*The xml document*
<?xml version="1.0" encoding="utf-8"?>
<codeBook xmlns="http://www.icpsr.umich.edu/DDI" >
<stdyDscr> ....
*the resulting xml document*
<?xml version="1.0" encoding="utf-8"?>
<codeBook xmlns="http://www.icpsr.umich.edu/DDI">
<docDscr xmlns:ddi="http://www.icpsr.umich.edu/DDI">
<citation>
...
</citation>
</docDscr>
<stdyDscr>
<citation>
<titlStmt>
<titl>Foo bar</titl>
</titlStmt>
</citation>
</stdyDscr>
</codeBook>
My problem is that I'm getting an extra
xmlns:ddi="http://www.icpsr.umich.edu/DDI" in the
docDscr element
even though I'm suppressing it in the excludes. Is
there any way
I can stop this from happening?
-Mark Diggory
Harvard MIT Data Center
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
XSL-List
info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list