Problems with multiple XSL Files

Help
Tobel
2004-09-24
2012-10-08
  • Tobel
    Tobel
    2004-09-24

    Hello

    I want to generate XHTML Files out of XML Files trough XSL 2.0. My Style Sheets is divided in two files. All XSL Files begin with

    <xsl:stylesheet
    version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:saxon="http://saxon.sf.net/"
    extension-element-prefixes="saxon">

    The main.xsl file has a template like this:
    <xsl:template match="Page">
    <xsl:result-document href="content.htm" format="xhtmlTransitional">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">

    ....

    &lt;body&gt;
      &lt;xsl:apply-templates/&gt;
    &lt;/body&gt;
    

    </html>
    </xsl:template>

    The other XSL File contains all content elements:
    <xsl:template match="heading">
    <h1><xsl:value-of "."/></h1>
    </xsl:template>
    <xsl:template match="paragraph">
    <p><xsl:value-of "."/></p>
    </xsl:template>

    Now, i if generate a XHTML File, i get following:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
    <head>
    ...
    </head>
    <body>
    <h1 xmlns="">Heading</h1>
    <p xmlns="">Paragraph</p>
    </body>
    </html>

    If i put all XSL elements in one file the attribute xmlns="" don't appear. What is the problem?

    Greetings,

    Tobias Dreyschultze, University of Oldenburg, Germany

     
    • Michael Kay
      Michael Kay
      2004-09-24

      When you use an unqualified name in a literal result element, for example <head> or <p>, then it goes in the default namespace declared in some containing element in the stylesheet module. Your two stylesheet modules (apparently) have different default namespace declarations, so the elements they generate are going in different namespaces: the <html> and <body> elements in the XHTML namespace, the <h1> and <p> elements in the null namespace. To get the <h1> and <p> elements in the null namespace (which is what you asked for), the serializer needs to undeclare the default namespace.

      You presumably want all the elements in the XHTML namespace, so the solution is to make that the default namespace in every stylesheet module.

      Michael Kay