Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you have XSL variables in the document() function?

Tags:

xml

xslt

This works just fine:

<xsl:variable 
     name="issue_info_file" 
     select="document('/issues/2010/12/08/info.xml')
                /page-components/issue-metadata-component/title"/>

But this does not:

<xsl:variable 
     name="issue_info_file" 
     select="string(concat($full_issue_path,'/info.xml'))"/>
<xsl:variable 
     name="issue_title" 
     select="document($issue_info_file)
                /page-components/issue-metadata-component/title"/>

Does anyone if this is even allowed in XSLT? If not, does anyone recommend a solution for opening files with a dynamic variable?

like image 942
HumanSky Avatar asked Sep 02 '25 05:09

HumanSky


2 Answers

I do not know if this issue is still open, but there does not seem to be an answer. I have this code working in my XSL file.

<xsl:variable name="docRoot">../sitemap/</xsl:variable>
<xsl:variable name="fullDocRoot" select="string(concat($docRoot,'sitemap.xml'))"/>
<xsl:for-each select="document($fullDocRoot)/root/sitemap/loc">

Hope that helps someone.

like image 123
DigitalDragon Avatar answered Sep 05 '25 00:09

DigitalDragon


Can you have XSL variables in the document() function?

Yes.

Using variables as arguments of the document() function is perfectly OK, provided the values of the arguments are of the type expected (such as a URI). Most probably the value of $full_issue_path when concatenated with '/info.xml' does not produce a valid URI or the correct URI.

You need to provide a complete example if you hope people to uncover your error.

like image 43
Dimitre Novatchev Avatar answered Sep 05 '25 01:09

Dimitre Novatchev