Subjects
Home
Xalan extension functions
Fomatting question serializing DOM with pretty print
xalan with pull parser
Cannot find the declaration
Apache Xalan drop support to run on JRE 1 1 x
Why does Doctype change processing of a document
Node set to XML string via Java extensions in Xalan J: possible?
Templates/Transformers + thread safety???
Problem evaluating xpath with muliple prefix with different namespace
remove an arbitrary attribute from xsl output
Xalan3 XSLT 2 0 XPath 2 0 support?
Problem using compiled translets with Xalan !!
Xalan and jstl 1 1 problem with transform tag
NullPointer in DOM2DTM getLocalName
URIResolvers base parameter with xsltc and cascaded imports
Performance problem for Xalan J on intel dual core
Standard libraries in JAXP?
Serializing a DOM tree to XML file, customize entities replacement
Library Conflict Involving BCEL Library
A question on how users are using <xsl:message >
Kevin Cormier as a new Apache Xalan J committer
Struggling to iterate over tokenized string
Xalan count() trouble
Problem with recursive xpath
Error when switching to java 1 5
document( ' ')
Problem with Xalan2 7 0 transformation
cr/lf options
entity encoded XML
can xalan transform 2 xml using one xslt?
Xalan J JIRA defect review Monday October 16, 2006 from 2:00 to 3:30 pm ED
xsl transform with cdata section elements
xslt parameters not expanded
Weird behavior of XPath evaluate()
How to avoid <xsl:message > instruction prints stylesheet file informations ?
Cannot find SimpleTransform subdirectory after installing Xalan J
recover from document not found exceptions
jdk1 5 and Xalan jar differences?
Performance Issue
Error/Bug adding floating point numbers
XPathAPI: eval exp using nodes with default namespace
modifying xalan to output invalid XML
NullPointerException
mege two separate xml nodes into one
Is this a XALAN document identification bug?
is StylesheetRoot really java io Serializable ?
transform() fails for DOMSource but succeeds for StreamSource
Thoughts on Transformer parameter passing
HELP, Xalan and jstl 1 1 problem with transformer
Problem with XPath namespace axis?
string utils:replace deleting search string if replacement string is an HTML
help with enumeration values pls
xalan 2 5 1 vs 2 7 performance question
How to insert/update in XML document
HTML Serialization and Handling of Ampersands in HREF Attributes
XHTML link tag stripping
SystemId Unknown; Line #24; Column #49; java lang NullPointerException
xpath text() help
Apostrophe problem with xalan 2 7 0
How to set variables in XML document?
Links
Home
Oracle database error code ...
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
Why does Doctype change processing of a document

Why does Doctype change processing of a document

2007-05-01       - By Ferdinand Soethe
Reply:     1     2     3     4     5     6     7  

I', processing the document below with Xalan and the template below
experience a funny effect that I cannot explain.

As long as I have the <!DOCTYPE-element in my document, processing will
correctly go as far as

> <xsl:template match="/">
>>      <xsl:choose>
>>         <xsl:when test="name(child::node())='html'">
>>                  <xsl:apply-templates/>
>>     </xsl:when>

but then apply templates will ignore the correct template

> <xsl:template match="html">

and jump to the default template right at the bottom
<xsl:template match="@*|*|text()|processing-instruction()|comment()">
and mess up the transformation.

As soon as I remove the <!DOCTYPE-element everything works just fine.

Can anybody tell me what I'm missing here?

Thanks,
Ferdinand


Document

> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE html
>      PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html>
>     <!-- Diese Datei ist die Leitseite des Kursprogramms und muss händisch
gepflegt werden -->
>     <head>
>         <title>Leitseite Gesamtprogramm</title>
>     </head>
>     <body
>         class="Leitseite_Gesamtprogramm">
>         <h1>Leitseite Gesamtprogramm</h1>
>         <?php phpinfo();
>     ?>
>         <p
>             class="Absatz">Sie befinden sich auf der Leitseite des
>             Gesamtprogramms des Bildungsvereins Hannover. </p>
>         <p
>             class="Absatz">Herzlich willkommen! </p>
>     </body>
> </html>

Template

> <?xml version="1.0"?>
> <xsl:stylesheet
>     version="1.0"
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
>     <xsl:key name="h2s" match="h2" use="generate-id(preceding-sibling::h1[1])
"/>
>     <xsl:key name="h3s" match="h3" use="generate-id(preceding-sibling::h2[1])
"/>
>     <xsl:key name="h4s" match="h4" use="generate-id(preceding-sibling::h3[1])
"/>
>     <xsl:key name="h5s" match="h5" use="generate-id(preceding-sibling::h4[1])
"/>
>     <xsl:key name="h6s" match="h6" use="generate-id(preceding-sibling::h5[1])
"/>
>
>     <xsl:template match="/">
>      <xsl:choose>
>         <xsl:when test="name(child::node())='html'">
>                  <xsl:apply-templates/>
>     </xsl:when>
>     <xsl:otherwise>
>       <document>
>        <header><title>Error in conversion</title></header>
>        <body>
>         <warning>This file is not in a html format, please convert manually.<
/warning>
>        </body>
>       </document>
>     </xsl:otherwise>
>      </xsl:choose>
>     </xsl:template>
>            
>     <xsl:template match="html">
>         <document>
>             <xsl:apply-templates/>
>         </document>
>     </xsl:template>
>
>     <xsl:template match="head">
>         <header>
>             <xsl:apply-templates/>
>         </header>
>     </xsl:template>
>        
>     <xsl:template match="meta">
>         <xsl:copy>
>             <xsl:apply-templates select="node()|@*"/>
>         </xsl:copy>
>     </xsl:template>  
>    
>     <!--infer structure from sibling headings-->
>     <xsl:template match="body">
>        <body>
>           <xsl:apply-templates select="*[1]" mode="next"/>
>           <xsl:call-template name="process_h1"/>
>        </body>
>     </xsl:template>
>    
>     <!-- process all of documents content -->
>     <xsl:template name="process_h1">
>         <!-- start with each h1-heading -->
>        <xsl:for-each select="h1">
>          <!-- wrap a section all around it's content -->
>          <section>
>              <xsl:choose>
>                  <xsl:when test="a/@(protected)">
>                      <xsl:attribute name="id"><xsl:value-of select="a/@(protected)"/
></xsl:attribute>
>                      <xsl:copy-of select="@(protected)|@(protected)" />
>                  </xsl:when>
>                  <xsl:otherwise>
>                      <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>                  </xsl:otherwise>
>              </xsl:choose>
>            
>            <!-- process heading text as title -->  
>            <title><xsl:apply-templates/></title>
>            <!-- process all non heading elements following the heading -->  
>            <xsl:apply-templates select="following-sibling::*[1]" mode="next"/>
>            <!-- then process all second level headings within this first
level heading -->  
>            <xsl:for-each select="key('h2s',generate-id(.))">
>              <section>
>                 <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>                <title><xsl:apply-templates/></title>
>                <xsl:apply-templates select="following-sibling::*[1]" mode=
"next"/>
>                <xsl:for-each select="key('h3s',generate-id(.))">
>                  <section>
>                    <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>                    <title><xsl:apply-templates/></title>
>                    <xsl:apply-templates select="following-sibling::*[1]"
>                                         mode="next"/>
>                    <xsl:for-each select="key('h4s',generate-id(.))">
>                      <section>
>                        <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />  
>                        <title><xsl:apply-templates/></title>
>                        <xsl:apply-templates select="following-sibling::*[1]"
>                                             mode="next"/>
>                        <xsl:for-each select="key('h5s',generate-id(.))">
>                          <section>
>                            <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />  
>                            <title><xsl:apply-templates/></title>
>                            <xsl:apply-templates select="following-sibling::*
[1]"
>                                                 mode="next"/>
>                            <xsl:for-each select="key('h6s',generate-id(.))">
>                              <section>
>                                <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />  
>                                <title><xsl:apply-templates/></title>
>                             <xsl:apply-templates select="following-sibling::*
[1]" mode="next"/>
>                              </section>
>                            </xsl:for-each>
>                          </section>
>                        </xsl:for-each>
>                      </section>
>                    </xsl:for-each>
>                  </section>
>                </xsl:for-each>
>              </section>
>            </xsl:for-each>
>          </section>
>        </xsl:for-each>
>     </xsl:template>
>    
>     <!--process each sibling in order until the next heading level-->
>
>     <xsl:template match="*" mode="next">
>        <xsl:if test="not( translate( local-name(.),'123456','' ) = 'h' )">
>          <xsl:apply-templates select="."/>
>          <xsl:apply-templates select="following-sibling::*[1]" mode="next"/>
>        </xsl:if>
>     </xsl:template>
>      
>     <xsl:template match="P|p">
>         <p>
>           <xsl:if test="@(protected)">
>             <xsl:attribute name="class"><xsl:value-of select="@(protected)"/></xsl
:attribute>
>           </xsl:if>
>             <xsl:copy-of select="@(protected)|@(protected)" />
>           <xsl:apply-templates/>
>         </p>
>     </xsl:template>
>    
>     <xsl:template match="img">
>        
>        <xsl:choose>
>       <xsl:when test="name(..)='section'">
>           <figure alt="{@(protected)}" src= "{@(protected)}">
>               <xsl:copy-of select="@(protected)|@(protected)|@(protected)|@(protected)|@(protected)" />
>           </figure>
>       </xsl:when>
>       <xsl:otherwise>
>          <img alt="{@(protected)}" src= "{@(protected)}">
>               <xsl:copy-of select="@(protected)|@(protected)|@(protected)|@(protected)|@(protected)" />
>           </img>
>       </xsl:otherwise>
>        </xsl:choose>
>        
>     </xsl:template>
>    
>     <xsl:template match="source|blockquote">
>       <xsl:choose>
>       <xsl:when test="name(..)='p'">
>        <code>
>            <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>          <xsl:value-of select="." />
>        </code>
>       </xsl:when>
>      
>       <xsl:otherwise>
>        <source>
>            <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>          <xsl:value-of select="." />
>        </source>
>       </xsl:otherwise>
>        </xsl:choose>
>     </xsl:template>
>
>  
>     <!-- convert a to link -->
>     <xsl:template match="a">
>      
>       <xsl:if test="@(protected)">
>         <!-- Attach an id to the current node -->
>         <xsl:attribute name="id"><xsl:value-of select="translate(@(protected), ' $',
'__')"/></xsl:attribute>
>         <xsl:apply-templates/>
>       </xsl:if>
>       <xsl:if test="@(protected)">
>           <link href="{@(protected)}">
>             <xsl:copy-of select="@(protected)|@(protected)|@(protected)|@(protected)|@(protected)" />
>           <xsl:apply-templates/>
>         </link>
>       </xsl:if>
>        
>     </xsl:template>
>    
>     <xsl:template match="@(protected) | @(protected)"/>
>        
>     <xsl:template match="center">
>       <xsl:choose>
>       <xsl:when test="name(..)='p'">
>          <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>          <xsl:apply-templates/>
>       </xsl:when>
>      
>       <xsl:otherwise>
>        <p>
>            <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>          <xsl:apply-templates/>
>        </p>
>       </xsl:otherwise>
>        </xsl:choose>
>     </xsl:template>
>
>     <xsl:template match="ol">
>       <xsl:choose>
>       <xsl:when test="name(..)='p'">
>         <xsl:text disable-output-escaping="yes"><![CDATA[</p>]]></xsl:text>
>          <ol>
>              <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>           <xsl:apply-templates/>
>          </ol>
>         <xsl:text disable-output-escaping="yes"><![CDATA[<p>]]></xsl:text>
>       </xsl:when>
>         <xsl:otherwise>
>          <ol>
>              <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>           <xsl:apply-templates/>
>          </ol>
>       </xsl:otherwise>
>        </xsl:choose>
>     </xsl:template>
>    
>     <xsl:template match="ul">
>       <xsl:choose>
>       <xsl:when test="name(..)='p'">
>         <xsl:text disable-output-escaping="yes"><![CDATA[</p>]]></xsl:text>
>          <ul>
>              <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>           <xsl:apply-templates/>
>          </ul>
>         <xsl:text disable-output-escaping="yes"><![CDATA[<p>]]></xsl:text>
>       </xsl:when>
>         <xsl:otherwise>
>          <ul>
>              <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>           <xsl:apply-templates/>
>          </ul>
>       </xsl:otherwise>
>        </xsl:choose>
>     </xsl:template>
>        
>     <xsl:template match="b">
>       <strong>
>         <xsl:value-of select = "."/>
>       </strong>
>     </xsl:template>
>    
>     <xsl:template match="i">
>       <em>
>           <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>         <xsl:value-of select = "."/>
>       </em>
>     </xsl:template>
>
>     <xsl:template match="u">
>       <u>
>           <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>         <xsl:value-of select = "."/>
>       </u>
>     </xsl:template>
>    
>     <xsl:template match="table">
>       <xsl:copy>
>         <xsl:copy-of select="@*"/>
>         <xsl:apply-templates/>
>       </xsl:copy>    
>     </xsl:template>
>    
>            
>     <xsl:template match="br">
>       <xsl:choose>
>      <xsl:when test="normalize-space(text())">
>            
>      <xsl:choose>
>        <xsl:when test="name(..)='p'">
>            
>            <xsl:apply-templates/>
>          <br>
>              <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>          </br>
>        </xsl:when>
>          <xsl:otherwise>
>          <p>
>              <xsl:apply-templates/>
>          </p>
>        </xsl:otherwise>
>         </xsl:choose>
>        
>      </xsl:when>
>        <xsl:otherwise>
>        <br>
>            <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>        </br>
>      </xsl:otherwise>
>        </xsl:choose>
>     </xsl:template>
>    
>     <!-- Strip -->
>     <xsl:template match="font|big">
>         <xsl:copy-of select="@(protected)|@(protected)|@(protected)" />
>       <xsl:apply-templates/>
>     </xsl:template>
>
>
>    
>
>    
>     <xsl:template match="@*|*|text()|processing-instruction()|comment()">
>         <xsl:message><xsl:value-of select="name(.)"/></xsl:message>
>       <xsl:copy>
>         <xsl:apply-templates select="@*|*|text()|processing-instruction()
|comment()"/>
>       </xsl:copy>
>     </xsl:template>
>
>
> </xsl:stylesheet>