2011-03-25 36 views
0

我在尋找一些幫助的XSL選擇:XSL在那裏聲明

我需要的是一個選擇,將顯示一個不同的列表標題在同一行的文檔匹配名稱字段。如果沒有條目,我會顯示一個鏈接來創建一個新鏈接。這裏是我有:

<xsl:choose> 
    <xsl:when test="/dsQueryResponse 
         /Change_Types 
          /Rows 
          /Row 
           /@Document = @Name"/> 
     <xsl:value-of select="/dsQueryResponse 
           /Change_Types 
            /Rows 
             /Row 
              /@Document[ 
               /dsQueryResponse 
               /Change_Types 
                /Rows 
                 /Row 
                  /@Document = @Name 
              ]"/> 
    </xsl:when> 
    <xsl:otherwise> 
     <!-- Code to show link --> 
    </xsl:otherwise> 
</xsl:choose> 

如果任何人都可以指出我要去哪裏錯了,將不勝感激!

+1

請張貼您輸入的XML。 – 2011-03-25 18:52:48

+2

該謂詞將始終爲false,因爲從來沒有'@ Document'屬性具有'@ Name'屬性。請發佈您的XML文檔。 – 2011-03-25 22:00:40

回答

0

以下是我的工作方式: 需要爲@FileLeafRef創建一個變量,以便可以保留該變量以在for-each內進行測試。

<xsl:variable name="document" select="@FileLeafRef"/> 

<xsl:choose> 
<!-- If there is an entry in the 'Tickets' list for this @FileLeafRef --> 
<xsl:when test="/dsQueryResponse/Tickets/Rows/Row/@Document = $document"> 
    <!-- Show it here --> 
    <xsl:for-each select="/dsQueryResponse/Tickets/Rows/Row"> 
     <xsl:if test="@Document = $document"> 
     <xsl:value-of select="@Title"/> 
    </xsl:if> 
     </xsl:for-each> 
</xsl:when> 
<!-- Else, show a link to add a new Ticket with the document auto-populated --> 
<xsl:otherwise> 
    <xsl:call-template name="addNewItemLink"> 
     <xsl:with-param name="list" select="'Tickets'"/> 
     <xsl:with-param name="document" select="@FileLeafRef"/> 
    </xsl:call-template> 
</xsl:otherwise> 
</xsl:choose> 
2

在沒有你的源XML它是一個完整的猜測,但我懷疑

@Document = @Name 

應該

@Document = current()/@Name 

兩個場合。除非您確實希望同一元素的DocumentName屬性具有相同的值。