[xsl] accessing multiple xml documents from within one template

Subject: [xsl] accessing multiple xml documents from within one template
From: Stefan Hunziker <stefan@xxxxxxxxxxxxx>
Date: Fri, 16 Jan 2009 00:08:51 +0100
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