Re: [xsl] document() function using variable

Subject: Re: [xsl] document() function using variable
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 14 May 2007 11:50:46 +0200
Vaduvoiu Tiberiu wrote:
Simple question to the point:

document('/folder/folder2/file.xml')/title work

but if I have a parameter "nm" with the value of "file" or a variable with the name of "nm" with the value of "file" then

document('/folder/folder2/$nm.xml')/title doesn't work. Why doesn't it work?? I tried googling "document() using parameter" and other ways but I didn't find anything usefull. Anyone can help me out?? 10x

'/folder/folder2/$nm.xml' is a string containing the '$' dollar sign (and hence, searches for a file with the name '$nm.xml', which is apparently not what you want). Luckily, it is not interpreted as a variable reference! How would the compiler know whether your variable is $nm, $nm.xml or even something else? You probably want to use concat, or something similar, which concatenates strings):


document(concat('/folder/folder2/', $nm, '.xml'))/title

Btw, some help for google: use the term "xslt how to concatenate strings" (without quotes). The first hits explain what you need to know.

Cheers,
-- Abel Braaksma

Current Thread