我有麻煩發生,其選擇在由位置不同的部分的XML文檔的一個節點的xpath表達式。我使用xsl:variable來創建表達式,但是當我使用xsl:for-each作爲我的select語句的xsl:變量的值時,我得到一個錯誤。
<xsl:variable name="input_params_query">
<xsl:text disable-output-escaping="yes">/example/inputs/dataset[</xsl:text>
<xsl:number value="position()" format="1" />
<xsl:text disable-output-escaping="yes">]/parameter</xsl:text>
</xsl:variable>
<xsl:for-each select="$input_params_query">
<input rdf:resource="#{@name}"/>
</xsl:for-each>
導致錯誤:
The 'select' expression does not evaluate to a node set.
當我打印出來的XSL的值變量我使用,我得到:
/example/inputs/dataset[1]/parameter
這是一個有效和正確的Xpath表達式我試圖在for-each調用中選擇節點。
是否將xsl:for-each select屬性的xsl:variable用法不正確?
背景和充分的解釋:
我使用XSLT來生成在以下XML結構的可用信息的RDF/XML表示。
在這種情況下,什麼XML實際上是指一個過程進行兩次;第一次生成輸出文件「a」和第二次生成輸出文件「b」。參數「p1」和「p2」是生成文件「a」的執行的輸入,參數「p3」是生成文件「b」的執行的輸入。
對於'process'的每個輸出,我都生成一個RDF個體併爲該流程執行定義輸入和輸出。基本上,我想將/ example/inputs/dataset [n] /參數中的所有值定義爲生成輸出/ example/process/outputs/file [n]的進程的輸入。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="//process">
<xsl:for-each select="outputs/*">
<!-- declare rdf resource of type Process, define Process outputs -->
<!-- ... this I already have working so I have withheld for brevity -->
<!-- define input parameters -->
<xsl:variable name="input_params_query">
<xsl:text disable-output-escaping="yes">/example/inputs/dataset[</xsl:text>
<xsl:number value="position()" format="1" />
<xsl:text disable-output-escaping="yes">]/parameter</xsl:text>
</xsl:variable>
<xsl:for-each select="$input_params_query">
<input rdf:resource="#{@name}"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
什麼XSLT引擎您使用的? – 2009-12-28 20:56:56