[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

In my main books.xml document being processed I have a number of
books, as follows:

		<title>The Perfume</title>

in a second reportDef.xml I want to define a report list, as follows:

	<col title="Book title" field="title" type="text"/>
	<col title="# pages" field="pagecount" type="number"/>		

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 match="book">
		<xsl:apply-templates select="$reportDef" mode="data"/>&#xA;
	<xsl:template match="col" mode="header">
		<xsl:value-of select="@title"/>; <!-- this one is no problem-->
	<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 -->

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

Current Thread