Page 1 of 1

Problem using variable to load document

Posted: Tue Mar 02, 2010 11:47 am
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

Re: Problem using variable to load document

Posted: Tue Mar 02, 2010 4:22 pm
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