RE: [xsl] Trouble with namespaces and running identity transform on XHTML

Subject: RE: [xsl] Trouble with namespaces and running identity transform on XHTML
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Thu, 11 Mar 2004 22:40:48 -0000
# 
# My reading of the XSLT 2.0 spec, or more to the point
# the XSLT 2.0 and XQuery 1.0 Serialization spec, is a
# bit more strongly worded than that. The XHTML output
# method is supposed to "output namespace declarations
# in a way that is consistent with the requirements of
# the XHTML DTD if this is possible."
# <http://www.w3.org/TR/xslt-xquery-serialization/#xhtml-output>

The fudge is in the phrase "if this is possible". The fact is that it's not
the serializer but the namespace fixup process that decides the prefixes to
use, so the "if this is possible" really means "if the serializer can
somehow conspire with the namespace fixup process to generate suitable
prefixes".

# So, if I'm looking at XSLT tools rather than some
# flavor of macros or Perl scripts (which are starting
# to look pretty good right now), my choices are
# 
# * write an XSLT 1.0 stylesheet so that when it is
# processed by an XSLT 1.0 processor, the serializer
# will never find adding namespace prefixes to be the
# path of least resistance. That seems to mean avoiding
# declaring a prefix for the XHTML namespace in the XSL
# stylesheet, and avoiding using the "namespace"
# attribute of xsl:element.

I would have expected that on most processors using
<xsl:element name="html" namespace="..xhtml.."> would produce no prefix, but
you appear to have found a counter-example. As I said, I don't think there
is a reliable solution that is guaranteed to work on every XSLT processor,
and that's as true of XSLT 2.0 as it is of 1.0. Sadly, XHTML violates the
assumptions behind the Xpath data model by requiring a specific (empty)
prefix.

Michael Kay


 # 
# * Use an XSLT processor that implements the
# almost-ready-for-primetime spec for XSLT 2.0. The main
# downsides to this are that the XSLT 2.0 spec is still
# in flux and that, AFAIK, there is only one stable XSLT
# processor that implements the XSLT 2.0 spec, namely
# Saxon. At least one upside is that I shouldn't need a
# separate filter (like HTML Tidy) to add whitespace
# before the "/>" in the tags for empty elements.
# 
# 
# __________________________________
# Do you Yahoo!?
# Yahoo! Search - Find what youre looking for faster
# http://search.yahoo.com
# 
#  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



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


Current Thread