RE: [xsl] Discovering the joys of xsl:include (Sovled!)

Subject: RE: [xsl] Discovering the joys of xsl:include (Sovled!)
From: Lukas Svoboda <LukasS@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 24 Apr 2001 17:03:24 +1200
Thanks to Tim Watts, Steve Muench and Josh Coltrane 
(from the XML list) for helping me with my include 
problems. For archive's sake I've documented the 
updated XSL files which now work perfectly:

XML File:

<?xml version="1.0"?>
<page_data>
  <header>
    <company_name>Company XYZ</company_name>
    <copyright>(C) Company XYZ, Blah Blah</copyright>
  </header>
  <products>
    <product>
      <product_id>1</product_id>
      <product_title>Product Title 1</product_title>
      <product_description>This is the description of the product
123456</product_description>
    </product>
    <product>
      <product_id>2</product_id>
      <product_title>Product Title 2</product_title>
      <product_description>This is the description of the product
435322</product_description>
    </product>
  </products>
</page_data>

XSL Main:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:msxsl="urn:schemas-microsoft-com:xslt">

  <xsl:import href="header.xsl" />

  <xsl:template match="/">
 
  <html>
  <body>

    <xsl:apply-templates select="page_data/header" />
    <br/>
    <table border="1" cellpading="4" cellspacing="4" bordercolor="#ffffff"
bgcolor="#BBBBBB">
      <xsl:apply-templates select="page_data/products/product" />
    </table>

  </body>
  </html>

  </xsl:template>

  <xsl:template match="product">

    <tr>
      <xsl:apply-templates select="product_id" />
      <xsl:apply-templates select="product_title" />
      <xsl:apply-templates select="product_description" />
    </tr>

  </xsl:template>

  <xsl:template match="product_id">
    <td><b><font face="verdana" color="#000033" size="2"><xsl:value-of
select="../product_id"/></font></b></td>
  </xsl:template>

  <xsl:template match="product_title">
    <td><b><font face="verdana" color="#000033" size="2"><xsl:value-of
select="../product_title"/></font></b></td>
  </xsl:template>

  <xsl:template match="product_description">
    <td><b><font face="verdana" color="#000033" size="2"><xsl:value-of
select="../product_description"/></font></b></td>
  </xsl:template>

</xsl:stylesheet>

XSL Include File:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt">

  <xsl:template match="header">
     <font face="verdana" color="#000033" size="3"><xsl:value-of
select="company_name"/></font><br/>
     <font face="verdana" color="#000033" size="1"><xsl:value-of
select="copyright"/></font><br/>
  </xsl:template>

</xsl:stylesheet>

> -----Original Message-----
> From: Tim Watts [mailto:timw@xxxxxxx]
> Sent: Tuesday, 24 April 2001 4:16 p.m.
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Discovering the joys of xsl:include
> 
> 
> Hi Lukus,
> 
> I can't see an xsl:include in your stylesheet, but the <xsl:import
> href="header.xsl" /> should be immediatly under the 
> <xsl:stylesheet>tag.
> (currently it is in a template)
> 
> For example, in a stylesheet I happen to have open at the 
> moment, it is
> writen like so...
> 
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:include href="document.xsl"/>
> <xsl:include href="common.xsl"/>
> 
>   <xsl:template match="/">
> ...
>   </xsl:template>
> etc.
> 
> The imports and includes must be defined before the templates.
> 
> Best of luck,
> Tim Watts :)

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread