No output from xalan when DOCTYPE declaration included

I

intrepidca

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

Philippe Poulard

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

George Bina

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top