Re: [xsl] XML source with DOCTYPE declaration

Subject: Re: [xsl] XML source with DOCTYPE declaration
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 20 Apr 2001 11:01:02 +0100
Hi Zeljko,

>> 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?

That's right - it adds the attribute that is the XHTML namespace
declaration to the document element (html).  Actually, given the other
entities I guess that you'll find something like:

<!ATTLIST %html.qname
   %XHTML.xmlns.attrib;>

but I'm just guessing here - the DTD for XHTML I have doesn't seem to
be as complex as the one you do.

> 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 ???

Sort of.  If you have an XHTML document that *doesn't* have the
DOCTYPE statement, then you need to explicitly give the namespace for
the XHTML rather than letting it be brought in from the DTD.  So it
should look like:

<html xmlns="http://www.w3.org/1999/xhtml";>
   ...
</html>

> 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>

You could do that or:

<xsl:template match="/html | /html:html">
   <xsl:text>html element found !!!</xsl:text>
</xsl:template>

Or even:

<xsl:template match="/*[local-name() = 'html']">
   <xsl:text>html element found !!!</xsl:text>
</xsl:template>

But it's better to use the XHTML namespace for the elements that are
part of XHTML, and it's obviously easier to write a stylesheet that
uses that namespace that one that covers both.  If you have both kinds
of documents, then you could do some preprocessing to move the
elements into that namespace.  If you have a stylesheet that just
looks has the following templates in it:

<xsl:template match="*">
   <xsl:element name="{local-name()}"
                namespace="http://www.w3.org/1999/xhtml";>
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />
   </xsl:element>
</xsl:template>

<xsl:template match="node()">
   <xsl:copy />
</xsl:template>

You could use this stylesheet to preprocess those XHTML files that
don't reference the DTD, to make them be 'proper' XHTML documents.

> 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.

>From the DTD?!?  That sounds very strange.  Could you give a sample
that shows that happening?  Which processor are you using?

> 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?

You could switch to a parser that ignores comments (although I don't
know any). But really you shouldn't worry about it too much - XSLT
processors are fairly good at ignoring the things that they don't
need, until they need them.

>> 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)?

No - there isn't even a working draft for XSLT 2.0 yet, only a set of
requirements for it, so there's no indication about *how* XSLT 2.0
will do anything, just that it *will*.  And therefore there aren't any
processors that support XSLT 2.0.

> Again many thanks for your help, I really appreciated it!

My pleasure :)

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread