OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: <xsl:insert> - Further Description - Simpler Example

[ Lists Home | Date Index | Thread Index ]
  • From: tpassin@home.com
  • To: "Xml-Dev@Xml. Org" <xml-dev@xml.org>
  • Date: Wed, 26 Jul 2000 00:16:46 -0400

Jim,

Here is a way to put a (well-formed) part of an xml file into an output file
wherever you want.  I think this will do what you want.  It's essentially an
"xsl:insert" substitute.

The example has a "content.xml" file that contains some html markup.  There
is a configuration file that contains information about the header, footer,
and content.  The stylesheet inserts the various bits of information at
different points within the output file, including echoing the "content"
file into the output.

These examples are simple, but I think they do everything you want.  The
only place you have to make changes for any specific set of pages is in the
config file.  This is what you want to do, you shouldn't be making changes
to your stylesheet(s) if you don't absolutely have to.

Below are given the content file, the config file, the stylesheet, and the
transformed result.
I used XT.  The command line is:

xt content.xml main.xsl

Cheers,

Tom Passin


//////content.xml //////
<content><h1 class='c1'>Content of document 1</h1>
This is the content of document 1
</content>
///////////////////////

//////config.xml ///////
<config>
 <header><bgcolor>red</bgcolor><title>Red Header</title></header>
 <content>content.xml</content>
 <footer><bgcolor>yellow</bgcolor></footer>
</config>
///////////////////////

///////// main.xsl ////////
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:variable name="config-file" select="document('config.xml')"/>

 <xsl:template match="/">
  Header color: <xsl:value-of select="$config-file//header/bgcolor"/>.
  Header text: <xsl:value-of select="$config-file//header/title"/>.

======= Content: ==========

<xsl:copy-of select="/content/node()"/>
======= End of content =========

  Footer color: <xsl:value-of select="$config-file//footer/bgcolor"/>.
 </xsl:template>
</xsl:stylesheet>
///////////////////////////

////////// OUTPUT /////////
D:>xt content.xml main.xsl

                Header color: red.
                Header text: Red Header.

======= Content: ==========

<h1 class="c1">Content of document 1</h1>
This is the content of document 1

======= End of content =========

                Footer color: yellow.
//////////////////////////////








 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS