2011-12-15 87 views
1


我試圖創建XSL轉換。 我的XML看起來是這樣的:使用XPATH和當前屬性名稱的XLST元素值

<DataRepository> 
    <Contents> 
    <Content uniqueID="1" name="some.name" ...> 
     <Description>Content description</Description> 
    </Content> 
    ... 
    </Contents> 
    <Tests> 
    <Test> 
     <Content uniqueID="1"/> 
     <Content uniqueID="2"/> 
     <Content uniqueID="N"> 
    </Test> 
    ... 
    </Tests> 
</DataRepository> 

在轉換後的文檔我想通過顯示內容描述來呈現的測試內容。
XLS片斷負責,這是:

<xsl:for-each select="DataRepository/Tests/Test"> 
    <h2><u><xsl:value-of select="@name"/></u></h2> 
    <ol> 
     <xsl:for-each select="Content"> 
     <li><xsl:value-of select="//DataRepository/Contents/ 
       Content[@uniqueID='{@uniqueID}']/Description"/></li> 
     </xsl:for-each> 
    </ol> 
    </xsl:for-each> 

我得到空行中顯示沒有描述的輸出。 如果我用實際的數字替換{@uniqueID}它的作品。

請問你能提出我做錯了什麼?

+0

源文檔的XML。你還可以舉一個你想要的輸出的例子嗎?目前還不清楚你認爲`{@uniqueID}`應該做什麼。 – 2011-12-15 15:31:42

回答

3

使用current()函數引用uniqueID屬性當前節點的:

沒有很好地形成
<xsl:value-of select="/DataRepository/Contents/ 
      Content[@uniqueID=current()/@uniqueID]/Description"/> 
+1

這解決了問題!謝謝! – alzix 2011-12-15 16:54:39