473,382 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Effect of DTD declaration on XSL processing?

Test Test HTML file

Test file to observe effect of DTD declaration on XSL processing.

Jul 20 '05 #1
5 2116
Simon Brooke <si***@jasmine.org.uk> writes:
(i) explain this behaviour and the reasons for it, and
Namespaces. In your XHTML with DTD, the html element and all its
descendents are in a namespace because of fixed-value attribute
declarations in the DTD. In the XHTML without DTD, the elements are
in no namespace.

In your XSLT, <xsl:template match="html"> matches only html elements
in no namespace.
(ii) suggest a recipe for XSLT stylesheets which work irrespective
of whether the DTD declaration is present or not?


I think the only way is change all your XPath expressions to match
against both possibilities. For example

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:ht="http://www.w3.org/1999/xhtml">
<xsl:template match="html | ht:html">
or
<xsl:template match="*[local-name() = 'html']">

--
Dean Tiegs, NE¼-20-52-25-W4
“Confortare et esto robustus”
http://telusplanet.net/public/dctiegs/
Jul 20 '05 #2
Dean Tiegs <da*******@telus.net> writes:
Simon Brooke <si***@jasmine.org.uk> writes:
(i) explain this behaviour and the reasons for it, and
Namespaces. In your XHTML with DTD, the html element and all its
descendents are in a namespace because of fixed-value attribute
declarations in the DTD. In the XHTML without DTD, the elements are
in no namespace.


Many thanks for that, that's clear and straightforward...
In your XSLT, <xsl:template match="html"> matches only html elements
in no namespace.
(ii) suggest a recipe for XSLT stylesheets which work irrespective
of whether the DTD declaration is present or not?


I think the only way is change all your XPath expressions to match
against both possibilities. For example

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:ht="http://www.w3.org/1999/xhtml">
<xsl:template match="html | ht:html">


OK, this works. The effect on performance is quite surprising:

-[simon]-> time xsltproc test.xsl with-dtd.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
matched html
-->

real 0m11.328s
user 0m0.020s
sys 0m0.020s

-[simon]-> time xsltproc test.xsl without-dtd.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
matched html
-->

real 0m0.005s
user 0m0.000s
sys 0m0.000s

Presumably the extra time is taken fetching and parsing the DTD. I
*hate* generating code which isn't valid, but I'm going to have to
make a choice here between valid code and reasonable performance!

--
si***@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/

;; my other religion is Emacs
Jul 20 '05 #3
In article <87************@gododdin.internal.jasmine.org.uk >,
Simon Brooke <si***@jasmine.org.uk> wrote:
real 0m11.328s
user 0m0.020s
sys 0m0.020s real 0m0.005s
user 0m0.000s
sys 0m0.000s Presumably the extra time is taken fetching and parsing the DTD.


Fetching, since the cpu time is still only .04 seconds.

Can't you use a catalog to get a local copy instead? Or failing that
an http proxy?

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #4
Simon Brooke wrote:
I thought I knew this stuff. I've been teaching XML since 1998. But
I've just stumbled on something which is so bizarre (to me) that I'm
beginning to think I don't understand anything at all.

Consider the attached files. They comprise one very simple XSL
transform, one copy of a very simple valid XHTML file with the DTD
declaration (without which it would not be valid), and one copy of the
same XHTML file but with the DTD declaration removed. Note that
with-dtd.html has been tested against the W3C validator.


According to the spezification you have no XHTML-Dokument
<http://www.w3.org/TR/xhtml1/#strict>:

3.
The root element of the document must contain an xmlns declaration for
the XHTML namespace [XMLNS]. The namespace for XHTML is defined to be
http://www.w3.org/1999/xhtml. An example root element might look like:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)

Jul 20 '05 #5
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
In article <87************@gododdin.internal.jasmine.org.uk >,
Simon Brooke <si***@jasmine.org.uk> wrote:
real 0m11.328s
user 0m0.020s
sys 0m0.020s

real 0m0.005s
user 0m0.000s
sys 0m0.000s

Presumably the extra time is taken fetching and parsing the DTD.


Fetching, since the cpu time is still only .04 seconds.

Can't you use a catalog to get a local copy instead? Or failing that
an http proxy?


Not reliably, in all the places this software runs. However, it turns
out not to matter very much because in the real application the time
hit occurs only the first time the DTD declaration is seen, and as
this software tends to have uptimes of more than six months a ten
second hit at startup time is not that painful. I'm just glad that I
now understand what's going on!

The only thing that bothers me is what happens if the software doesn't
have access to the public internet at all and consequently can't fetch
the DTD. Presumably it will barf horribly and I'll have to do
something about that.

The easiest thing, of course, would be to not generate the DTD
declaration in the first place, but for purely aesthetic reasons I
don't want to do that!

--
si***@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/

;; my other religion is Emacs
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jan Nordgreen | last post by:
In my main.php I have this doc declaration at the top: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Later in main.php I use...
3
by: Sarah Haskins | last post by:
I have a few questions about this problem I'm having involving XML, DTD, and XSL. I'm working with this DTD which defines a stylesheet, as such... <?xml version="1.0" encoding="UTF-8"?>...
4
by: Helmut Dirtinger | last post by:
Hi Compontents of an xml file are mapped to the different node types of the xpath data model. An element is mapped to an element node, an attribute node represents an attribute and its value...
6
by: David B. Bitton | last post by:
I am having a problem deserializing XML when the root node is missing a namespace declaration. My Type has an XmlTypeAttribute with a namespace defined. If I attempt to deserialize the XML, I get...
1
by: George1776 | last post by:
Background: I have taken an excel spreadsheet with the formatting I want, saved it as XML, then converted it to an XSL document to use it as a sort of template. Added some for-each select...
24
by: Daniel Antonson | last post by:
What is the effect of the following code? char Ch; Ch = '7'; printf("%d\n", Ch);
2
by: Alan Searle | last post by:
I have built several simple XML/XSL reports and so far have put the declaration of the style sheet (xsl) in the header of the XML file. e.g. <?xml version="1.0" encoding="iso-8859-1"?>...
5
by: Dennis Benzinger | last post by:
How can I copy the xml declaration from one document to another document using XSLT? (Use case: I have a xml document where I just want to add a processing instruction without modifing the rest...
14
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; int main() { int i;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.