代码之家  ›  专栏  ›  技术社区  ›  Kev Hunter

如何在列表中执行选项

  •  1
  • Kev Hunter  · 技术社区  · 16 年前

    伪码

    If Domain inList(GB,US,ES,FR Then
       Print This Html
    Else
      Print This HTML
    EndIf
    
    4 回复  |  直到 11 年前
        1
  •  4
  •   annakata    16 年前

    这是一个 非常 一般形式,但在设计时不知道列表的情况下,只要可以获得对表示列表的节点集的引用,就可以执行以下简单测试:

    <xsl:when test="$listset/item[@property=$variable]">
    

    其中,对于XML,假设$variable=/foo/bar/@property和$listset=/foo/list

    <?xml version="1.0"?>
    <foo>
      <bar property="gb" />
      <list>
        <item property="gb"/>
        <item property="us"/>
      </list>
    </foo>
    
        2
  •  1
  •   annakata    16 年前

    xsl:choose. the spec here

    <xsl:choose>
      <xsl:when test="domain = 'GB' or domain = 'US' or domain = 'ES' or domain = 'FR'">
        print this html
      </xsl:when>
      <xsl:otherwise>
        print other html
      </xsl:otherwise>
    </xsl:choose>
    
        3
  •  0
  •   BeWarned    16 年前

    如果在给定文件的情况下使用XSLT2.0

    您可以使用以下内容:
    <xsl:template match="list/item">
    Property [<xsl:value-of select="@property"/>] html
    </xsl:template>

    <xsl:template match="list/item[some $x in ('us', 'gb') satisfies $x eq @property ]">
    Property [<xsl:value-of select="@property"/>] HTML
    </xsl:template>

        4
  •  0
  •   Dimitre Novatchev    16 年前

    就是要有一个选项字符串,用来比较 domain . 然后是以下XPath表达式(在 @test 属性 <xsl:if> <xsl:when> true() 确切地说,当 领域

    contains(' GB US ES ', concat(' ', domain, ' '))

    领域 . 如果不能保证这一点,XPath表达式还可以验证此要求:

    not(contains(domain, ' '))
    and
    包含('GB US ES',concat('',域,'))