xsl-list
[Top] [All Lists]

Re: Is exclude-result-prefixes wise in XHTML-to-XHTML transformations?

2004-03-11 13:10:50

--- David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk> wrote:
  So that reads to me like exclude-result-prefixes
will
  work for an XSL transform that copies nodes in the
  XHTML namespace from input to output, but might
  monkey-wrench a transform of nodes in the null
  namespace to nodes in the XHTML namespace. Is that
  correct?

No, exclude-result-prefixes never gives the system
licence to change the
namespace of an element or attribute.
It only stops
namespace nodes
being copied to the result tree because they happen
to be in scope from
somewher higher in the stylesheet. Any element
that's in a namespace (or
in no namespace) so all elements and attributes will
_always_ have
whatever namespace nodes needed to correctly
interpret the name.

In other words, if I have an element with a namespace
node with the URI "http://www.w3.org/1999/xhtml"; in
the result tree, putting
xmlns:h="http://www.w3.org/1999/xhtml"; and
exclude-result-prefixes="h" in the stylesheet will
*not* shear the element of all namespace nodes with
the URI "http://www.w3.org/1999/xhtml";, whether or not
the element was copied from the source tree or created
by the XSL transform.

That only partially answers my question of why this 

<xsl:transform
   xmlns:h="http://www.w3.org/1999/xhtml";
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   exclude-result-prefixes="h"
   version='1.0'>

<xsl:output method="xml"/>

<xsl:template match="h:h1">
<p xmlns="http://www.w3.org/1999/xhtml";>
   <xsl:apply-templates select="@*" />
   LOOK MA! <xsl:apply-templates /> NO BRAINS!
</p>
</xsl:template>

<!-- Identity transform snipped -->

produces this

<html xmlns="http://www.w3.org/1999/xhtml";>
--snip--
<p class="test_h1_attr">
   LOOK MA! Sample H1 NO BRAINS!
</p>
--snip--

on four out of four XSLT processors I've tried when
applied to this strictly conforming XHTML document

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

<html xmlns="http://www.w3.org/1999/xhtml";>
--snip--
<h1 class="test_h1_attr">Sample H1</h1>
--snip--

Yet when this

<xsl:transform
   xmlns="http://www.w3.org/1999/xhtml";
   xmlns:h="http://www.w3.org/1999/xhtml";
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   exclude-result-prefixes="h"
   version='1.0'>
 
<xsl:output method="xml"/>
 
<xsl:template match="h:h1">
<p>
   <xsl:apply-templates select="@*" />
   LOOK MA! <xsl:apply-templates /> NO BRAINS!
</p>
</xsl:template>

<!-- Identity transform snipped -->

is applied to the same strictly conforming XHTML
document, it only produces this

<html xmlns="http://www.w3.org/1999/xhtml";>
--snip--
<p class="test_h1_attr">
   LOOK MA! Sample H1 NO BRAINS!
</p>
--snip--

on three out of four XSLT processors I've tried, with
Saxon being the holdout. Saxon produces this

<html xmlns="http://www.w3.org/1999/xhtml";>
--snip--
<p xmlns:h="http://www.w3.org/1999/xhtml";
class="test_h1_attr">
   LOOK MA! Sample H1 NO BRAINS!
</p>
--snip--

which, though not what I want, is legal according to
the XSLT 1.0 spec
<http://www.biglist.com/lists/xsl-list/archives/200310/msg01126.html>.

Now as far as I can tell, both transforms have the
same thing in common, namely that elements are created
in the result tree that require the very namespace
nodes, the ones with the URI
"http://www.w3.org/1999/xhtml";, that the
exclude-result-prefixes attribute requests be
excluded. Trouble is, I'm trying to figure out whether
the former transform works because of some special
rule in the XSLT spec that I couldn't see, or because
the serializers of the XSLT processors were being
gracious.


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you?re looking for faster
http://search.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list