C
chris
Hi,
I would like to take two documents and combine them. I can do this but
I'm having a little problem with namespaces again. The input documents
namespace is xhtml, but how do I tell the processor what namespace to
use for the sourced document (the one read by document())?
Just now it outputs
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample</title>
</head>
<body>
<div id="leftcontent">
<!-- this is the stuff taken from the document menu.xml -->
<body xmlns=""> <===== PROBLEM
<p class="navig-header">
Web
</p>
</body>
</div>
<div id="rightcontent">
<!-- this is taken from the input file specified to the parser -->
<p class="sample-header">
Sample text
</p>
</div>
</body>
</html>
Aside from the fact it outputs the body of the menu.xml document, I
don't want it to output the xmlns="". How can this be done? Can the
result be copied into a variable and the template applied to that?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xslutput
method = "xhtml"
version = "1.0"
omit-xml-declaration = "no"
encoding = "UTF-8"
indent = "yes"
doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system =
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<!-- matches root
-->
<xsl:template match="/xhtml:">
<html>
<xsl:apply-templates select="/xhtml:html/head" />
<xsl:apply-templates select="/xhtml:html/body" />
</html>
</xsl:template>
<!-- matches body
-->
<xsl:template match="xhtml:body">
<!-- output <body> <div id="leftcontent"> -->
<xsl:text disable-output-escaping="yes">
<body>
<div id="leftcontent">
</xsl:text>
<!-- output menu -->
<xsl:apply-templates select="document('menu.xml')/html/body" />
<!-- output </div> -->
<xsl:text disable-output-escaping="yes">
</div>
</xsl:text>
<!-- output <div id="rightcontent"> -->
<xsl:text disable-output-escaping="yes">
<div id="rightcontent">
</xsl:text>
<!-- output rest of body section -->
<xsl:apply-templates />
<!-- output </div> -->
<xsl:text disable-output-escaping="yes">
</div>
</xsl:text>
<!-- output </body> -->
<xsl:text disable-output-escaping="yes"></body></xsl:text>
</xsl:template>
<!-- matches anything that isn't covered by a template,
and copies it exactly
-->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:transform>
I would like to take two documents and combine them. I can do this but
I'm having a little problem with namespaces again. The input documents
namespace is xhtml, but how do I tell the processor what namespace to
use for the sourced document (the one read by document())?
Just now it outputs
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample</title>
</head>
<body>
<div id="leftcontent">
<!-- this is the stuff taken from the document menu.xml -->
<body xmlns=""> <===== PROBLEM
<p class="navig-header">
Web
</p>
</body>
</div>
<div id="rightcontent">
<!-- this is taken from the input file specified to the parser -->
<p class="sample-header">
Sample text
</p>
</div>
</body>
</html>
Aside from the fact it outputs the body of the menu.xml document, I
don't want it to output the xmlns="". How can this be done? Can the
result be copied into a variable and the template applied to that?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xslutput
method = "xhtml"
version = "1.0"
omit-xml-declaration = "no"
encoding = "UTF-8"
indent = "yes"
doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system =
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<!-- matches root
-->
<xsl:template match="/xhtml:">
<html>
<xsl:apply-templates select="/xhtml:html/head" />
<xsl:apply-templates select="/xhtml:html/body" />
</html>
</xsl:template>
<!-- matches body
-->
<xsl:template match="xhtml:body">
<!-- output <body> <div id="leftcontent"> -->
<xsl:text disable-output-escaping="yes">
<body>
<div id="leftcontent">
</xsl:text>
<!-- output menu -->
<xsl:apply-templates select="document('menu.xml')/html/body" />
<!-- output </div> -->
<xsl:text disable-output-escaping="yes">
</div>
</xsl:text>
<!-- output <div id="rightcontent"> -->
<xsl:text disable-output-escaping="yes">
<div id="rightcontent">
</xsl:text>
<!-- output rest of body section -->
<xsl:apply-templates />
<!-- output </div> -->
<xsl:text disable-output-escaping="yes">
</div>
</xsl:text>
<!-- output </body> -->
<xsl:text disable-output-escaping="yes"></body></xsl:text>
</xsl:template>
<!-- matches anything that isn't covered by a template,
and copies it exactly
-->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:transform>