替代打破每个循环XSLT

时间:2015-09-17 02:01:14

标签: xml xslt xml-namespaces

我试图找到针对特定条件的每个循环中的第一个匹配。在XML数据中,可能有多个匹配,我只需要一个。我知道你可以为每个循环设置条件,但我发现这个XML的语法非常困难。

XML:

<ns0:qualification_list>
  <ns0:qualification>
    <ns0:qualification_name>Master of Health Information Management</ns0:qualification_name>
    <ns0:qualification_sequence>0001</ns0:qualification_sequence>
    <ns0:is_english>N</ns0:is_english>
    <ns0:qualification_country>Australia</ns0:qualification_country>
    <ns0:where_obtained>University of Sydney</ns0:where_obtained>
    <ns0:mark/>
  </ns0:qualification>
  <ns0:qualification>
    <ns0:qualification_name>Bachelor of Health Science (Nursing)</ns0:qualification_name>
    <ns0:qualification_sequence>0002</ns0:qualification_sequence>
    <ns0:is_english>N</ns0:is_english>
    <ns0:qualification_country>Austria</ns0:qualification_country>
    <ns0:where_obtained>University of New South Wales</ns0:where_obtained>
    <ns0:mark/>
  </ns0:qualification>
</ns0:qualification_list>

XSL:

<xsl:for-each select="somedo:qualification_list">
        <xsl:for-each select="somedo:qualification">
            <xsl:if test="somedo:is_english = 'N'">
                <xsl:value-of select="somedo:where_obtained" />
            </xsl:if>
        </xsl:for-each> 
</xsl:for-each>

1 个答案:

答案 0 :(得分:2)

不需要 - 每个。

<xsl:value-of select="somedo:qualification_list/somedo:qualification[somedo:is_english = 'N']/somedo:where_obtained"/>