No output from xalan when DOCTYPE declaration included

Discussion in 'XML' started by intrepidca@gmail.com, Feb 15, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. 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 !
     
    Philippe Poulard, Feb 15, 2006
    #2
    1. Advertising

  3. George Bina Guest

    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
     
    George Bina, Feb 15, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ray Tayek
    Replies:
    13
    Views:
    2,971
    Ray Tayek
    Dec 2, 2003
  2. Mark Parnell
    Replies:
    1
    Views:
    370
    Luigi Donatello Asero
    Jul 8, 2003
  3. Isofarro
    Replies:
    4
    Views:
    405
    Isofarro
    Jul 9, 2003
  4. cvissy
    Replies:
    0
    Views:
    640
    cvissy
    Nov 16, 2004
  5. Larry Lindstrom
    Replies:
    19
    Views:
    1,359
    Jonathan N. Little
    Jun 12, 2012
Loading...

Share This Page