Problem using variable to load document

Here should go questions about transforming XML with XSLT and FOP.
mjaaland
Posts: 1
Joined: Tue Mar 02, 2010 11:34 am

Problem using variable to load document

Post by mjaaland »

Hi!

I wish to load code from a document, and I wish to store the file name in a variable.

For testing, I use a hardcoded file name, and to test it I also print it using value-of, as shown below.

<xsl:variable name="filename" select="'file.xml'" />
<xsl:value-of select="$filename" />

Note the single quotes I added in line one here, otherwise _nothing would print_ using value-of.

Then, to load the code:

<xsl:copy-of select="document($filename)" />

NO code is loaded here, I get a blank response. However, the following DOES work:
<xsl:copy-of select="document('file.xml')" />

I have tried so many combinations of quotes that I do not know if this is the problem, thought it seems likely. Please help.

Full code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xi="http://www.w3.org/2001/XInclude"
version="1.0"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:template match="/">

<xsl:variable name="filename" select="'file.xml'" />
<xsl:value-of select="$filename" />
<xsl:copy-of select="document($filename)" />

</xsl:template>
</xsl:stylesheet>

Please help me :)

Bendik
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: Problem using variable to load document

Post by george »

Hi,

I cannot reproduce any issue with the code you included. Please make sure you have the file.xml file in the same folder as the stylesheet.

Best Regards,
George
George Cristian Bina
Post Reply