2011-01-24 70 views
1

这只是正常:您可以在document()函数中使用XSL变量吗?

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

但这并不:

<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"/> 

有谁如果这是即使在XSLT允许吗?如果没有,有没有人推荐使用动态变量打开文件的解决方案?

+0

没有理由不应该工作,除非你的`$ full_issue_path`变量当然包含错误的值。你可以在输出中打印`$ issue_info_file`的值来看看它的评估结果是什么? – biziclop 2011-01-24 16:55:36

+1

可能使用{} thingy – Treemonkey 2011-01-24 16:56:19

回答

1

您可以在 document()函数中使用XSL变量吗?

使用变量作为document()函数的参数是完全可以的,只要参数的值是期望的类型(例如URI)即可。当与'/info.xml'连接时,最有可能的值为$full_issue_path不会产生有效的URI或正确的URI。

如果你希望人们发现你的错误,你需要提供一个完整的例子

4

我不知道这个问题是否仍然存在,但似乎没有答案。我有这个代码在我的XSL文件中工作。

<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"> 

希望能帮助别人。

相关问题