Re: [xsl] xml include

Subject: Re: [xsl] xml include
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 11 Apr 2001 13:34:26 +0100

> Thanx, this worked.
> But I inserted the line
>       <xinclude:include href="xml2.xml"/>
> after the first include to xml file and insterted another line
>     <H2><xsl:value-of select="$x//author2"/></H2>
> to xsl. (xml2.xml contains author2). The value of author2 returned is null.
> How can I access second included file ?

It depends a bit what how you want to work. You are using the so called
"pull" method in which you basically have everything in one template and
use value-of to pull in bits of data.

Which processor are you using, because I think that it should have
worked anyway because $x should contain a root node for each included
document, and so value-of select="$x//author2" should give you the
string value of the first ,author2 element in any of those documents
(although you don't have conrol over which document, if you do it like
that)



However the way I would normally do these things is the "push" method 
where you have lots of templates, so in this case

<xsl:stylesheet version='1.0'
    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
       xmlns:xinclude="http://www.w3.org/1999/XML/xinclude";>

    <xsl:output method="html" />

<xsl:template match="document">
 <html>
 <body>
<xsl:apply-templates/>
 </body>
 </html>
</xsl:template>

<xsl:template match="xinclude:include">
  <xsl:apply-templates select="document(@href)"/>
</xsl:template>

<xsl:template match="author">
 <h2><xsl:value-of select="."/></h2>
</xsl:template>

<xsl:template match="title">
 <h1><xsl:value-of select="."/></h1>
</xsl:template>

and so on. just adding templates for whatever you need.
Note that the template for xml include doesn't actually add anything to
the output it just moves the context for the apply-templates over to the
document specified.

David


_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp

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


Current Thread