2011-01-24 72 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"> 

希望能幫助別人。

相關問題