p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: Include/Import Question


Message #1 by "William Clark" <William.Clark@s...> on Tue, 25 Jun 2002 16:15:15
Your import statement has to be first (before the xsl:output statement), and
remove " match="/"  " from the named template definition as it's not
applicable.

If I save the following as getdata.xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

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

    <xsl:output method="html"/>

    <xsl:template match="/">

        <HTML>
            <HEAD><TITLE>Table Management Distribution System - Data
Page</TITLE></HEAD>
            <BODY>
                This is a test to see if stuff shows up.<br/>
                <xsl:call-template name="included_template"/>
            </BODY>
        </HTML>

    </xsl:template>

</xsl:stylesheet>

And in the same folder the following as getdata2.xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

    <xsl:template name="included_template">

        <H1><b>STUFF</b></H1>

    </xsl:template>

</xsl:stylesheet>

It appears to work fine...

...sam

----- Original Message -----
From: "William Clark" <William.Clark@s...>
To: "P2P_XSLT" <xslt@p...>
Sent: Tuesday, June 25, 2002 3:11 PM
Subject: [xslt] RE: Include/Import Question


> Mike,
>
> Thanks for responding.  I've tried calling a template after doing the
> import/include and it does not work.  If I use a named template
>
> <?xml version="1.0"?>
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:output method="html"/>
>
> <xsl:import href="getdata2.xsl"/>
> <xsl:template match="/">
> <HTML>
> <HEAD><TITLE>Table Management Distribution System - Data
> Page</TITLE></HEAD>
> <BODY>
> This is a test to see if stuff shows up.<br/>
> <xsl:call-template name="included_template" />
> </BODY>
> </HTML>
> </xsl:template>
>
> <xsl:template name="included_template" match="/">
> <H1><b>STUFF</b></H1>
> </xsl:template>
>
> </xsl:stylesheet>
>
> within the same file it works.  If I delete the "included_template" and
> put it in the import/include file I do not get to it when it is called
> even after I put in an apply-imports statement.
>
>
> -------------------------------------------------------
> <xsl:include> is always used as a top-level element (a child of
> xsl:stylesheet). Its effect is to incorporate the top-level elements
> (variables, template rules, key definitions etc) from another stylesheet
> module.
>
> You can't have raw text at the top level of a stylesheet module, it's
> got to go inside a variable or template.
>
> Michael Kay
> Software AG
> home: Michael.H.Kay@n...
> work: Michael.Kay@s...
>
> > -----Original Message-----
> > From: William Clark [mailto:William.Clark@s...]
> > Sent: 25 June 2002 16:15
> > To: P2P_XSLT
> > Subject: [xslt] Include/Import Question
> >
> >
> > I am trying to create a suite of xslt files that create HTML
> > web pages and I want the same beginning and end for each
> > page.  After reading the
> > book I get the idea that an include or import will pull in code from
> > another xslt file, but it does not seem to do it.  For example:
> >
> > My "include" file is:
> >
> > <?xml version="1.0"?>
> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > version="1.0">
> > This is also a test.<br/>
> > </xsl:stylesheet>
> >
> > My "main" file is:
> >
> > <?xml version="1.0"?>
> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > version="1.0">
> > <xsl:output method="html"/>
> > <xsl:template match="/">
> > <HTML>
> > <HEAD><TITLE>Data Page</TITLE></HEAD>
> > <BODY>
> > <xsl:include href="getdata2.xsl"/>
> > This is a test to see if stuff shows up.<br/>
> > </BODY>
> > </HTML>
> > </xsl:template>
> > </xsl:stylesheet>
> >
> > I tried an include with an apply-includes statement and it
> > did not work any better - I only get the html saying this is
> > a test to see if...
> >
> > Ideas/suggestions are welcome.
> >
> >
>
>


  Return to Index