1

我想知道以下是否可能。我想检查这些条件中的任何一个是否返回为是以打印该语句。

想知道写这个的最好方法是什么。谢谢

<li>
    <xsl:choose>
        <xsl:when test="overdraftmoreaffordable/option [@id='yes']='selected' or businessmoreaffordable/option [@id='yes']='selected' or farmermoreaffordable/option [@id='yes']='selected' or loanprimiummoreaffordable/option [@id='yes']='selected' or loanmoreaffordable/option [@id='yes']='selected' or baseloanmoreaffordable/option [@id='yes']='selected' or termloanprimiummoreaffordable/option [@id='yes']='selected' or termmoreaffordable/option [@id='yes']='selected' or variablemoreaffordable/option [@id='yes']='selected' or fixedloanmoreaffordable/option [@id='yes']='selected'">Statement One</xsl:when>
        <xsl:otherwise>Statement Two</xsl:otherwise>
    </xsl:choose>
</li>

或者即使我只想确定是否有任何条件是,最好还是单独执行语句打印语句。

谢谢

添加:

这似乎正是我所需要的,但我的代码被分成很多单独的页面,所以我认为他们无法沟通以了解是否在其他页面中选择了“是”

<xsl:if test="overdraft &gt; 0">
        <div style="margin-top: 0cm; margin-bottom: 0cm;">
            <br/>
            <b>Overdraft</b><br/>
            An Overdraft allows your current account to go into an overdrawn position up to an agreed limit.<br/>
        </div>

        <xsl:for-each select="overdrafts/overdraftdata">

            <div style="margin-top: 0cm; margin-bottom: 0cm;">
                <br/>
                This product is suitable because;
                <ul>
                    <li>You are seeking a lending product for the purpose of <xsl:value-of select="overdraftpurpose"/></li>
                    <li>You are seeking a total amount of credit of EUR <xsl:value-of select="overdraftamount"/></li>
                    <li><xsl:choose>
                            <xsl:when test="*[substring(local-name(), string-length(local-name()) - 9) = 'affordable']/option[@id='yes']='selected'">
                                Repayment of the debt has been structured in a manner that is more affordable given your current circumstances
                            </xsl:when>
                            <xsl:otherwise>
                                You are likely to be able to repay the debt in the manner required under the credit agreement
                            </xsl:otherwise>
                        </xsl:choose>
                    </li>
                    <li>It is available for the term you require</li>
                </ul>
            </div>

        </xsl:for-each>

    </xsl:if>

    <xsl:if test="businesscreditline &gt; 0">

        <div style="margin-top: 0cm; margin-bottom: 0cm;">
            <br/>
            <b>Business Credit Line</b><br/>
            A Business Credit Line provides you with the convenience and flexibility of a pre-arranged line of 
            credit. It will facilitate improved budgeting and will give you greater choice in meeting your working
            capital and short term funding needs<br/>
        </div>

        <xsl:for-each select="businesscreditlines/businesscreditlinedata">

            <div style="margin-top: 0cm; margin-bottom: 0cm;">
                <br/>
                This product is suitable because;
                <ul>
                    <li>You are seeking a lending product for the purpose of <xsl:value-of select="businesspurpose"/></li>
                    <li>You are seeking a total amount of credit of EUR <xsl:value-of select="businessamount"/></li>
                    <li><xsl:choose><xsl:when test="*[substring(local-name(), string-length(local-name()) - 9) = 'affordable']/option[@id='yes']='selected'">Repayment of the debt has been structured in a manner that is more affordable given your current circumstances</xsl:when><xsl:otherwise>You are likely to be able to repay the debt in the manner required under the credit agreement</xsl:otherwise></xsl:choose></li>
                    <li>It is available for the term you require</li>
                </ul>
            </div>

        </xsl:for-each>

    </xsl:if>'
4

2 回答 2

2

好吧,如果您的测试正在测试所有可能的子元素,您可以将其简化为

 <xsl:when test="*/option[@id='yes']='selected'">Statement One</xsl:when>

这将检查当前元素的所有子元素。

如果您想更具体,并且只检查名称以“负担得起”结尾的元素,您可以这样做

 <xsl:when test="
     *[substring(local-name(), string-length(local-name()) - 9) = 'affordable']
     /option[@id='yes']='selected'">
   Statement One
 </xsl:when>

这是假设 XSLT1.0。在 XSLT2.0 中,您可以通过使用“ends-with”函数来简化这一点。

<xsl:when test="
    *[ends-with(local-name(),'affordable')]/option [@id='yes']='selected'">
  Statement One
</xsl:when>
于 2012-11-20T12:25:21.863 回答
1

你可以说压缩一下

(overdraftmoreaffordable | businessmoreaffordable | farmermoreaffordable |
  loanprimiummoreaffordable | loanmoreaffordable| baseloanmoreaffordable |
  termloanprimiummoreaffordable | termmoreaffordable | variablemoreaffordable |
  fixedloanmoreaffordable)/option[@id='yes']='selected'

如果节点集中的任何节点具有等于给定字符串的值,则=利用节点集和字符串之间的比较为真这一事实。或者,如果您正在做的是枚举包含子字符串“moreaffordable”的所有可能元素名称,那么您可以逃脱

*[contains(local-name(), 'moreaffordable')]/option[@id='yes'] = 'selected'
于 2012-11-20T12:30:10.217 回答