You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Dan Evans <de...@invores.com> on 2005/08/17 16:21:17 UTC
Additional Info for XALANJ-2032
This appears to be covered by XALANJ-2032, so the following is
supplemental info. The idea is to remove the namespace declarations
from the output root element using exclude-result-prefixes as specified
in the XSLT 1.0 spec Section 7.1.1. This problem was produced by
XALAN-J 2.7.0.
---Stylesheet---
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:conf="http://www.testxsl.org/2005/conformance"
xmlns="http://www.testxsl.org/1999/ournamespace"
exclude-result-prefixes="#default conf"
version="1.0">
<xsl:output cdata-section-elements="script"/>
<!-- Copy everything that doesn't match other rules -->
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- strip comments -->
<xsl:template match="comment()"/>
<!-- Success criteria -->
<xsl:template match="conf:pass">
<prompt>pass</prompt>
<exit/>
</xsl:template>
<!-- Failure criteria -->
<xsl:template match="conf:fail">
<prompt>fail</prompt>
<exit/>
</xsl:template>
</xsl:stylesheet>
---Instance Document---
<?xml version="1.0"?>
<root version="2.0"
xmlns="http://www.testxsl.org/1999/ournamespace"
xmlns:conf="http://www.testxsl.org/2005/conformance">
<catch>
<conf:fail expr="'document caught event ' + _event"/>
</catch>
</root>
---Output---
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.testxsl.org/1999/ournamespace"
xmlns:conf="http://www.testxsl.org/2005/conformance" version="2.0">
<catch>
<prompt>fail</prompt><exit/>
</catch>
</root>
---Desired Output---
<?xml version="1.0" encoding="UTF-8"?>
<root version="2.0">
<catch>
<prompt>fail</prompt><exit/>
</catch>
</root>
----------------
Dan Evans
Re: Additional Info for XALANJ-2032
Posted by da...@us.ibm.com.
> david_n_bertoni@us.ibm.com wrote:
> >>This appears to be covered by XALANJ-2032, so the following is
> >>supplemental info. The idea is to remove the namespace declarations
> >>from the output root element using exclude-result-prefixes as
specified
> >>in the XSLT 1.0 spec Section 7.1.1. This problem was produced by
> >>XALAN-J 2.7.0.
> >
> >
> > exclude-result-prefixes only works for namespace declarations that are
not
> > required in the serialized result tree. Also, it does not affect
> > namespaces copied from the source tree using xsl:copy.
>
> The conf: elements are "meta-elements" that are expanded by the
> stylesheet.
I don't know what you mean by the term "meta-elements" -- that term is not
used anywhere in the XSLT recommendation.
When this template in your stylesheet is instantiated, you are creating
element and text nodes in the results tree:
> <!-- Success criteria -->
> <xsl:template match="conf:pass">
> <prompt>pass</prompt>
> <exit/>
> </xsl:template>
The XSLT recommendation defines calls the "prompt" and "exit" elements
literal result elements:
http://www.w3.org/TR/xslt#literal-result-element
Because you have a default namespace declaration in your stylesheet, the
"prompt" and "exit" elements have a namespace URI of
"http://www.testxsl.org/1999/ournamespace". When the result tree is
serialized, the serializer will have to generate a namespace declaration
for the default namespace when necessary.
> There are NO conf: elements in the result tree and as such,
> the xmlns:conf declaration is not required at the root element of the
> result tree.
It's not there because it's "required," it's there because your stylesheet
copied it to the result tree through xsl:copy, which also copies any
namespace nodes:
http://www.w3.org/TR/xslt#copying
"The xsl:copy element provides an easy way of copying the current node.
Instantiating the xsl:copy element creates a copy of the current node. The
namespace nodes of the current node are automatically copied as well, but
the attributes and children of the node are not automatically copied."
> This was exactly what I was hoping exclude-result-prefixes
> would eliminate, and it doesn't appear to. It is harmless if the
> default xlmns declaration is placed on the output root element since the
> entire output tree is in a single (the default) namespace, but it would
> be nice if exclude-result-prefixes="#default" actually had that effect,
> as appears to be suggested by XSLT 1.0 7.1.1 xsl:copy is used in order
> for the stylesheet to be insensitive to the elements of the input
> document other than the conf: elements.
As I said previously, exclude-result-prefixes cannot exclude a namespace
node that is required. If it didn't copy the namespace node that binds
the default namespace to "http://www.testxsl.org/1999/ournamespace," the
names of the nodes created by the literal result elements would change.
> If you feel my argument has flaws, could you indicate how the desired
> result can be achieved
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:conf="http://www.testxsl.org/2005/conformance"
exclude-result-prefixes="conf"
version="1.0">
<xsl:output cdata-section-elements="script"/>
<!-- copy PIs -->
<xsl:template match="processing-instruction()">
<xsl:copy/>
</xsl:template>
<!-- strip comments -->
<xsl:template match="comment()"/>
<!-- create an attribute, using only the local part of the
expanded name of the matched attribute -->
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<!-- create an element, using only the local part of the
expanded name of the matched element -->
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<!-- Success criteria -->
<xsl:template match="conf:pass">
<prompt>pass</prompt>
<exit/>
</xsl:template>
<!-- Failure criteria -->
<xsl:template match="conf:fail">
<prompt>fail</prompt>
<exit/>
</xsl:template>
</xsl:stylesheet>
Dave
Re: Additional Info for XALANJ-2032
Posted by Dan Evans <de...@invores.com>.
I take your point about the Mulberry Technology list, but since you were
gracious enough to respond, I'd like to follow up. The point you made
below about exclude-result-prefixes is exactly my question. See inline.
david_n_bertoni@us.ibm.com wrote:
>>This appears to be covered by XALANJ-2032, so the following is
>>supplemental info. The idea is to remove the namespace declarations
>>from the output root element using exclude-result-prefixes as specified
>>in the XSLT 1.0 spec Section 7.1.1. This problem was produced by
>>XALAN-J 2.7.0.
>
>
> exclude-result-prefixes only works for namespace declarations that are not
> required in the serialized result tree. Also, it does not affect
> namespaces copied from the source tree using xsl:copy.
The conf: elements are "meta-elements" that are expanded by the
stylesheet. There are NO conf: elements in the result tree and as such,
the xmlns:conf declaration is not required at the root element of the
result tree. This was exactly what I was hoping exclude-result-prefixes
would eliminate, and it doesn't appear to. It is harmless if the
default xlmns declaration is placed on the output root element since the
entire output tree is in a single (the default) namespace, but it would
be nice if exclude-result-prefixes="#default" actually had that effect,
as appears to be suggested by XSLT 1.0 7.1.1 xsl:copy is used in order
for the stylesheet to be insensitive to the elements of the input
document other than the conf: elements.
If you feel my argument has flaws, could you indicate how the desired
result can be achieved
Dan
>
>><?xml version="1.0" encoding="UTF-8"?>
>><root xmlns="http://www.testxsl.org/1999/ournamespace"
>>xmlns:conf="http://www.testxsl.org/2005/conformance" version="2.0">
>> <catch>
>> <prompt>fail</prompt><exit/>
>> </catch>
>></root>
>
>
> Given your input and document and stylesheet, this is the correct result.
>
>
>><?xml version="1.0" encoding="UTF-8"?>
>><root version="2.0">
>> <catch>
>> <prompt>fail</prompt><exit/>
>> </catch>
>></root>
>
>
> If you don't want elements in the namespace "
> http://www.testxsl.org/1999/ournamespace", you can't use xsl:copy. Also,
> the literal result elements in your stylesheet are in that namespace as
> well, since you have a default namespace in your stylesheet.
>
> For general XSLT questions, I always recommend the Mulberry Technologies
> XSL list, along with the XSL FAQ:
>
> http://www.mulberrytech.com/xsl/
> http://www.dpawson.co.uk/xsl/xslfaq.html
>
> Dave
>
>
Re: Additional Info for XALANJ-2032
Posted by da...@us.ibm.com.
> This appears to be covered by XALANJ-2032, so the following is
> supplemental info. The idea is to remove the namespace declarations
> from the output root element using exclude-result-prefixes as specified
> in the XSLT 1.0 spec Section 7.1.1. This problem was produced by
> XALAN-J 2.7.0.
exclude-result-prefixes only works for namespace declarations that are not
required in the serialized result tree. Also, it does not affect
namespaces copied from the source tree using xsl:copy.
> <?xml version="1.0" encoding="UTF-8"?>
> <root xmlns="http://www.testxsl.org/1999/ournamespace"
> xmlns:conf="http://www.testxsl.org/2005/conformance" version="2.0">
> <catch>
> <prompt>fail</prompt><exit/>
> </catch>
> </root>
Given your input and document and stylesheet, this is the correct result.
> <?xml version="1.0" encoding="UTF-8"?>
> <root version="2.0">
> <catch>
> <prompt>fail</prompt><exit/>
> </catch>
> </root>
If you don't want elements in the namespace "
http://www.testxsl.org/1999/ournamespace", you can't use xsl:copy. Also,
the literal result elements in your stylesheet are in that namespace as
well, since you have a default namespace in your stylesheet.
For general XSLT questions, I always recommend the Mulberry Technologies
XSL list, along with the XSL FAQ:
http://www.mulberrytech.com/xsl/
http://www.dpawson.co.uk/xsl/xslfaq.html
Dave