combining two documents

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">

<xsl:eek:utput
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">
&lt;body&gt;
&lt;div id="leftcontent"&gt;
</xsl:text>

<!-- output menu -->
<xsl:apply-templates select="document('menu.xml')/html/body" />

<!-- output </div> -->
<xsl:text disable-output-escaping="yes">
&lt;/div&gt;
</xsl:text>


<!-- output <div id="rightcontent"> -->
<xsl:text disable-output-escaping="yes">
&lt;div id="rightcontent"&gt;
</xsl:text>

<!-- output rest of body section -->
<xsl:apply-templates />

<!-- output </div> -->
<xsl:text disable-output-escaping="yes">
&lt;/div&gt;
</xsl:text>

<!-- output </body> -->
<xsl:text disable-output-escaping="yes">&lt;/body&gt;</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>
 
C

chris

Dimitre said:
There are at least two syntactical/semantic errors in your stylesheet:




the value of the "method" attribute cannot be 'xhtml'.

It can in XSL 2.0 draft and this is supported by Saxon. However I have
changed this to xml below, it only changes the output indentation.

This is not a valid match pattern.


Therefore, the code is not the same as the one you are talking about
(because the latter produced result, not error messages).

Please, provide the real code.

The problem has changed after making some changes (fixing the syntax),
it outputs nothing for the second document at all.


<?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">

<xsl:eek:utput
method = "xml"
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">
&lt;body&gt;
&lt;div id="leftcontent"&gt;
</xsl:text>

<!-- output menu -->
<xsl:apply-templates select="document('menu.xml')"/>

<!-- output </div> -->
<xsl:text disable-output-escaping="yes">
&lt;/div&gt;
</xsl:text>


<!-- output <div id="rightcontent"> -->
<xsl:text disable-output-escaping="yes">
&lt;div id="rightcontent"&gt;
</xsl:text>

<!-- output rest of body section -->
<xsl:apply-templates />

<!-- output </div> -->
<xsl:text disable-output-escaping="yes">
&lt;/div&gt;
</xsl:text>

<!-- output </body> -->
<xsl:text disable-output-escaping="yes">&lt;/body&gt;</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>

Also, you didn't provide the two xml documents.

-- Input xhtml given to parser...
--

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample</title>
<link rel="stylesheet" type="text/css" href="sample.css" />
</head>
<body>
<p class="sample-header">
Sample text
</p>

<!-- bunch of text -->
<p>
Sample page text
</p>
</body>
</html>


-- file read by document() function
--
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>menu</title>
</head>
<body>
<p class="navig-header">
Web
</p>
<p class="navig-menu">
<a href="xhtml/index.html">XHTML</a>
</p>
</body>
</html>


-- Output
--
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Sample</title>

<link rel="stylesheet" type="text/css" href="sample.css"/>

</head>

<body>
<div id="leftcontent">

</div>

<div id="rightcontent">

<p class="sample-header">
Sample text
</p>

<!-- bunch of text -->

<p>
Sample page text
</p>

</div>
</body>
</html>


Thanks,
Chris
 
D

Dimitre Novatchev

Nothing has changed, this:
<xsl:template match="xhtml:">

is an attempt to define a template with invalid match pattern. An error
message to this effect is generated by MSXML4 and JD, other XSLT processors
(Saxon, XalanJ) simply crash.

Could you, please correct this and try again?


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top