473,410 Members | 1,976 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,410 software developers and data experts.

No output from xalan when DOCTYPE declaration included

When I try to translate an XML file (using
org.apache.xalan.xslt.Process) that has a DOCTYPE declaration, I only
get the <?xml ...?> processing instruction in the output file. I get
no error messages. If I remove the DOCTYPE declaration it works fine.
I have checked that the XML file is valid according to the DTD (using
xmllint) and that checks out. Here are snippets from the XML and the
XSL files and debugging output from xalan:

the XML:
-----------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resume PUBLIC "-//Sean Kelly//DTD Resume 1.5.1//EN"
"http://xmlresume.sourceforge.net/dtd/resume.dtd">

<resume>
[CHILDREN OMITTED]
</resume>
-----------------------

and the XSL (the lines were numbered to match the debugging output
below):
-----------------------
1: <?xml version="1.0" encoding="UTF-8"?>
2:
3: <xsl:stylesheet version="1.0"
4: xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
5:
6: <xsl:template match="*"/>
7: <xsl:template match="*" mode="header"/>
8:
9: <xsl:template match="/">
10: <xsl:apply-templates select="resume"/>
11: </xsl:template>
12:
13: <xsl:template match="resume">
14: <xlatex version="1.0">
15: <xsl:if test="@id">
16: <newcommand name="resid"><xsl:value-of
select="@id"/></newcommand>
17: </xsl:if>
18: <xsl:apply-templates select="lastModified"
mode="header"/>
19: <xsl:apply-templates select="copyright" mode="header"/>
20: <xsl:apply-templates select="header/*" mode="header"/>
21: <environment name="resume">
22: <body>
23: <xsl:apply-templates/>
24: </body>
25: </environment>
26: </xlatex>
27: </xsl:template>
28:
[REMAINDER OMITTED]
622: </xsl:stylesheet>
-----------------------

Here is the debugging output from xalan (using the options -TT -TS -TG
-TTC):
-----------------------
file:///home/brad/work/resume/resume-latex.xsl Line #9, Column #26:
template match='/'
file:///home/brad/work/resume/resume-latex.xsl Line #10, Column #41:
apply-templates
Selected source node '#document', at file
'file:///home/brad/work/resume/resume.xml', line #-1, column #-1
file:///home/brad/work/resume/resume-latex.xsl Line #10, Column #41:
apply-templates, select='null':
[empty node list]
STARTDOCUMENT
ENDDOCUMENT
-----------------------

Feb 15 '06 #1
2 2307
Hi,

The problem is that your DTD defines a fixed attribute that is in fact
a default namespace declaration that puts all the document elements in
the http://xmlresume.sourceforge.net/resume/0.0 namespace:

<!ATTLIST resumes id ID #IMPLIED
xmlns CDATA #FIXED "http://xmlresume.sourceforge.net/resume/0.0"
xmlns:xsi CDATA #FIXED "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation CDATA #IMPLIED>

Your stylesheet works if the elements are in no namespace but after
adding the DOCTYPE declaration all your elements are in the
http://xmlresume.sourceforge.net/resume/0.0 namespace thus the name
tests from your stylesheet will not match any element from the document
anymore.

The best approach is to always add the namespace declaration that is
defined as a fixed attribute in the DTD in your document, so you should
always have:

<resume xmlns="http://xmlresume.sourceforge.net/resume/0.0">
[CHILDREN OMITTED]
</resume>

and change your stylesheet to handle the elements in your namespace
instead of elements in no namespace.

The simplest way to accomplish that is to move to XSLT 2.0 and change
only

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

to

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xpath-default-namespace="http://xmlresume.sourceforge.net/resume/0.0">
In XSLT 1.0 there is no possibility to set the default namespace for
XPath so all the name tests that use unqualified names will test for
elements in non namespace. If you need to remain on XSLT 1.0 then you
need to declare the http://xmlresume.sourceforge.net/resume/0.0
namespace and map it to a prefix, let's say p and then add the prefix
to all the name tests from your stylesheet, for instance instead of
<xsl:template match="resume">
you should have:
<xsl:template match="p:resume">
etc.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Feb 15 '06 #2
in********@gmail.com wrote:
When I try to translate an XML file (using
org.apache.xalan.xslt.Process) that has a DOCTYPE declaration, I only
get the <?xml ...?> processing instruction in the output file. I get
no error messages. If I remove the DOCTYPE declaration it works fine.
I have checked that the XML file is valid according to the DTD (using
xmllint) and that checks out. Here are snippets from the XML and the
XSL files and debugging output from xalan:
hi,

the DTD defines some fixed attributes values :

<!ATTLIST resume id ID #IMPLIED
xmlns CDATA #FIXED "http://xmlresume.sourceforge.net/resume/0.0"
xmlns:xsi CDATA #FIXED "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation CDATA #IMPLIED>

thus, <resume> stand for <resume
xmlns="http://xmlresume.sourceforge.net/resume/0.0">

but you try to match "resume" that is not bound to a namespace URI ; you
must declare it in your stylesheet :

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:res="http://xmlresume.sourceforge.net/resume/0.0">

[...]

<xsl:apply-templates select="res:resume"/>

[...]

<xsl:template match="res:resume">

don't try to omit the prefix "res", as unprefixed names are never bound
to a namespace URI in XPath

the XML:
-----------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resume PUBLIC "-//Sean Kelly//DTD Resume 1.5.1//EN"
"http://xmlresume.sourceforge.net/dtd/resume.dtd">

<resume>
[CHILDREN OMITTED]
</resume>
-----------------------

and the XSL (the lines were numbered to match the debugging output
below):
-----------------------
1: <?xml version="1.0" encoding="UTF-8"?>
2:
3: <xsl:stylesheet version="1.0"
4: xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
5:
6: <xsl:template match="*"/>
7: <xsl:template match="*" mode="header"/>
8:
9: <xsl:template match="/">
10: <xsl:apply-templates select="resume"/>
11: </xsl:template>
12:
13: <xsl:template match="resume">
14: <xlatex version="1.0">
15: <xsl:if test="@id">
16: <newcommand name="resid"><xsl:value-of
select="@id"/></newcommand>
17: </xsl:if>
18: <xsl:apply-templates select="lastModified"
mode="header"/>
19: <xsl:apply-templates select="copyright" mode="header"/>
20: <xsl:apply-templates select="header/*" mode="header"/>
21: <environment name="resume">
22: <body>
23: <xsl:apply-templates/>
24: </body>
25: </environment>
26: </xlatex>
27: </xsl:template>
28:
[REMAINDER OMITTED]
622: </xsl:stylesheet>
-----------------------

Here is the debugging output from xalan (using the options -TT -TS -TG
-TTC):
-----------------------
file:///home/brad/work/resume/resume-latex.xsl Line #9, Column #26:
template match='/'
file:///home/brad/work/resume/resume-latex.xsl Line #10, Column #41:
apply-templates
Selected source node '#document', at file
'file:///home/brad/work/resume/resume.xml', line #-1, column #-1
file:///home/brad/work/resume/resume-latex.xsl Line #10, Column #41:
apply-templates, select='null':
[empty node list]
STARTDOCUMENT
ENDDOCUMENT
-----------------------

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
Feb 15 '06 #3

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

Similar topics

1
by: Bekkali Hicham | last post by:
hi, i have already used xalan several times with success, but i have a error message that i don't understand, thanks for your help (Emplacement inconnu de l'erreur) Erreur XSLT...
0
by: Francesc Guim Bernat | last post by:
Dear colleagues, i'm getting in troubles using one XML library with Visual Studio .NET and Xerces with Xalan. (Xercer 2.4 and Xalan 1.7) When i execute the code i get the next run time error: ...
3
by: johkar | last post by:
What is the proper doctype syntax for XHTML transitional??? Strict? How come XSLT doesn't preserve XHTML when it is compiled (Xalan)? Meaning, <br /> tags become <br> <input /> tags become...
3
by: Avalon1178 | last post by:
Hi, I recently downloaded the xalan-c source code in http://mirrors.ccs.neu.edu/Apache/dist/xml/xalan-c I followed the instructions from the apache site on how to build it (I already have...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
17
by: Rick Brandt | last post by:
We are using a JS popup calendar in our pages and find that we get various JS errors whenever we call the code from an HTML page that includes a DOCTYPE. The specific type doesn't seem to matter. ...
3
by: Jeff Calico | last post by:
Hello everyone I am transforming an XML document to text, basically only outputting a small portion of it. When I run the following XSLT via Xalan's processor, I get a bunch of unwanted blank...
0
drhowarddrfine
by: drhowarddrfine | last post by:
The Doctype or DTD Many coders get confused by all the talk of doctypes and how they affect browsers and the display of their web pages. This article will get right to the point about doctypes...
6
by: John Larson | last post by:
Hi All, I am some information from INSPEC database records in XML to build a relational database of my own. I am currently trying to extract information by doing an XSLT transform of the XML...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.