Can you have XSL variables in the document() funct

2019-07-22 04:54发布

问题:

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?

回答1:

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.



回答2:

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.



标签: xml xslt