Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > No output from xalan when DOCTYPE declaration included

Reply
Thread Tools

No output from xalan when DOCTYPE declaration included

 
 
intrepidca@gmail.com
Guest
Posts: n/a
 
      02-15-2006
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: xmlnssl="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
-----------------------

 
Reply With Quote
 
 
 
 
Philippe Poulard
Guest
Posts: n/a
 
      02-15-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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"
xmlnssi 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"
xmlnssl="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: xmlnssl="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 !
 
Reply With Quote
 
 
 
 
George Bina
Guest
Posts: n/a
 
      02-15-2006
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"
xmlnssi 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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

to

<xsl:stylesheet version="2.0"
xmlnssl="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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS Newbie - CSS Works With Invalid DOCTYPE. Fails With Valid DOCTYPE. Larry Lindstrom HTML 19 06-12-2012 02:07 PM
Upgrade of Xalan 1.2.2 and Xerces 1.4.4 to Xalan 2.6 and Xerces 2.6.2 cvissy XML 0 11-16-2004 07:06 AM
validate xml with scgema using sax gets a: "Valid documents musthave a <!DOCTYPE declaration." Ray Tayek Java 13 12-02-2003 02:17 PM
Re: What is wrong with this doctype declaration? Isofarro HTML 4 07-09-2003 06:52 PM
Re: What is wrong with this doctype declaration? Mark Parnell HTML 1 07-08-2003 10:30 AM



Advertisments