Problems with multiple XSL Files

  • Tobel


    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

    version="2.0" xmlns:xsl=""

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




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

    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" "">
    <html xmlns="" xml:lang="de" lang="de">
    <h1 xmlns="">Heading</h1>
    <p xmlns="">Paragraph</p>

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


    Tobias Dreyschultze, University of Oldenburg, Germany

    • Michael Kay
      Michael Kay

      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