XSL在哪里声明

时间:2011-03-25 18:48:23

标签: xslt select where

我正在寻找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>

如果有人能指出我哪里出错了,我们将不胜感激!

2 个答案:

答案 0 :(得分:2)

在没有源XML的情况下,这是一个完整的猜测,但我怀疑

@Document = @Name

应该是

@Document = current()/@Name
两次都是这样的。除非您确实希望同一元素的DocumentName属性具有相同的值。

答案 1 :(得分: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>
相关问题