[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] accessing multiple xml documents from within one template


Subject: Re: [xsl] accessing multiple xml documents from within one template
From: Ganesh Babu N <nbabuganesh@xxxxxxxxx>
Date: Fri, 16 Jan 2009 09:47:55 +0530

As per my understanding the input is books.xml  and output is reportDef.xml.

You have to write the templates matching books.xml and wrap the
content with the reporDef elements/attributes.

If you have multiple XML files as input you should use  collection() of xslt2

Regards,
Ganesh


On Fri, Jan 16, 2009 at 4:38 AM, Stefan Hunziker <stefan@xxxxxxxxxxxxx> wrote:
> hi
>
> In my main books.xml document being processed I have a number of
> books, as follows:
>
> <books>
>        <book>
>                <title>Hamlet</title>
>                <author>Shakespeare</author>
>                <publisher>Peares</publisher>
>                <pagecount>120</pagecount>
>                <weight>500g</weight>
>        </book>
>        <book>
>                <title>The Perfume</title>
>                <author>Sueskind</author>
>                <publisher>ABC</publisher>
>                <pagecount>230</pagecount>
>                <weight>256g</weight>
>        </book>
> </books>
>
> in a second reportDef.xml I want to define a report list, as follows:
>
> <reportDef>
>        <col title="Book title" field="title" type="text"/>
>        <col title="# pages" field="pagecount" type="number"/>
> </reportDef>
>
>
> Now, with xsl I like to generate a report. Until now it looks like:
>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>        <xsl:output  method="text" indent="no" encoding="ISO-8859-1"/>
>        <xsl:variable name="reportDef" select="document('reportDef.xml')"/>
>
>        <xsl:template match="books">
>                <xsl:apply-templates select="$reportDef" mode="header"/>&#xA;
>                <xsl:apply-templates select="book"/>
>        </xsl:template>
>
>        <xsl:template match="book">
>                <xsl:apply-templates select="$reportDef" mode="data"/>&#xA;
>        </xsl:template>
>
>        <xsl:template match="col" mode="header">
>                <xsl:value-of select="@title"/>; <!-- this one is no problem-->
>        </xsl:template>
>
>        <xsl:template match="col" mode="data">
>                <xsl:variable name="fieldname" select="@field"/>;
>                <!-- here I want to print the book property $fieldname, but I can't
> access the main xml books -->
>        </xsl:template>
> </xsl:stylesheet>
>
>
> The problem is, that I don't see the books.xml from within the
> reportDef templates (<xsl:template match="col" mode="data">). Also
> when I pass the book node by param to the template there is no content
> in this node!
>
> I would be very happy if anybody could give me a hint
>
> Thanks very much
> Stefan


Current Thread
Keywords