This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XML source with DOCTYPE declaration
Hi Jeni,
first of all thanks for your help. All just works as you described. :)
Still I got some questions left to which you maybe/hopefully could give
an answer.
> You'll probably find somewhere else something that looks approximately
> like:
>
> <!ATTLIST html
> %XHTML.xmlns.attrib;>
No, I couldn't find such a statement. This as far as I understand is
some kind of 'global' namespace declaration for html, isn't it? The
XHTML DTD instead seems to add the namespace to every HTML element
separately. For example I found the following DTD statements:
<!ENTITY % h4.qname "%XHTML.pfx;h4">
<!ENTITY % h5.qname "%XHTML.pfx;h5">
<!ENTITY % h6.qname "%XHTML.pfx;h6">
<!ENTITY % hr.qname "%XHTML.pfx;hr">
<!ENTITY % p.qname "%XHTML.pfx;p">
So is my assumption correct?
> Now, having that default namespace declaration means that in fact all
> the elements in your XHTML document are considered to be in the XHTML
> namespace. The XPaths that you use in the stylesheet have to select
> or match the elements *in that namespace*, rather than in the null
> namespace.
>
> So, in your stylesheet, you need to declare the XHTML namespace *with
> a prefix*. Usually you do that in the xsl:stylesheet element. You
> then, whenever you refer to one of those XHTML elements, need to use
> that prefix with the name of the element. So your stylesheet should
> look something like:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:html="http://www.w3.org/1999/xhtml">
>
> <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
>
> <xsl:template match="/">
> <xsl:text>ROOT element found !</xsl:text>
> <xsl:apply-templates/>
> </xsl:template>
>
> <!-- Note - html element is in the XHTML namespace, so you
> need to use the 'html' prefix -->
> <xsl:template match="/html:html">
> <xsl:text>HTML tag found !!!</xsl:text>
> </xsl:template>
> </xsl:stylesheet>
So does this mean there is no way to use one stylesheet for both kind of
XHTML files - with and without a DOCTYPE statement including the XHTML
DTD ??? Or do I really have to 2 template matches to make sure that
woth type of XHTML documents are transformed correctly. For example:
<xsl:template match="/html">
<xsl:text>HTML tag found !!!</xsl:text>
</xsl:template>
<xsl:template match="/html:html">
<xsl:text>HTML tag found !!!</xsl:text>
</xsl:template>
> When you use xsl:copy-of, then it does a deep copy of the node you
> select, including all the namespace nodes on the elements that it
> finds. You'd hope that an XSLT processor would recognise the fact
> that if the parent element has an equivalent namespace declaration,
> then it doesn't need to add the namespace node, but obviously not with
> the processor that you're using.
Ok, I think I understand. Another unwanted thing I noticed with the
<xsl:copy-of> was that all XML comments from the DTD are being printed.
So I assume that for every XML comment the XSLT parser creates a
separate node in the tree. If this is a fact, the performance and memory
footprint of the XLST parser probably will be getting worse.
So is there maybe a way to tell the parser to ignore all comments,
whether written in the XML document self or the documents DTD?
> In XSLT 2.0, there will be support for you to specify that the default
> namespace should be used in the interpretation of XPaths... but not
> yet.
Are the any XSLT engines which already support XSLT 2.0 (partly)?
Again many thanks for your help, I really appreciated it!
Zeljko
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list