combining two documents

Discussion in 'XML' started by chris, Jul 31, 2003.

  1. chris

    chris Guest

    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>
     
    chris, Jul 31, 2003
    #1
    1. Advertising

  2. chris

    chris Guest

    Dimitre Novatchev wrote:
    > There are at least two syntactical/semantic errors in your stylesheet:
    >
    >
    >> <xsl:eek:utput
    >> method = "xhtml"

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


    >> <xsl:template match="/xhtml:">

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

    </xsl:transform>


    > 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
     
    chris, Jul 31, 2003
    #2
    1. Advertising

  3. 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



    "chris" <> wrote in message
    news:5k6Wa.1775$...
    > Dimitre Novatchev wrote:
    > > There are at least two syntactical/semantic errors in your stylesheet:
    > >
    > >
    > >> <xsl:eek:utput
    > >> method = "xhtml"

    > >
    > >
    > > 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.
    >
    >
    > >> <xsl:template match="/xhtml:">

    > >
    > >
    > > 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>
    >
    > </xsl:transform>
    >
    >
    > > 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
    >
     
    Dimitre Novatchev, Jul 31, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. williams
    Replies:
    1
    Views:
    908
  2. Winterminute

    Combining Two Data Sources for one Data List

    Winterminute, Dec 3, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    838
    Winterminute
    Dec 3, 2003
  3. Chuck
    Replies:
    0
    Views:
    384
    Chuck
    Aug 28, 2003
  4. Replies:
    1
    Views:
    490
    Juan T. Llibre
    Oct 18, 2006
  5. stolirx

    combining .rtf documents

    stolirx, Mar 4, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    333
    Mark Rae [MVP]
    Mar 5, 2008
Loading...

Share This Page