xslt选择多个OR条件时

时间:2012-11-20 12:05:35

标签: xslt

我想知道以下是否可行。我想检查是否有任何这些条件返回为是打印语句。

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

<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>'

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:1)

你可以通过说

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

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

*[contains(local-name(), 'moreaffordable')]/option[@id='yes'] = 'selected'