Muenchian Grouping XSLT



这是我的XML:

<LIGHT_DESCRIPTION_LIST>
    <LIGHT_DESCRIPTION>
        <LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
        <LIGHT_CATEGORY>17</LIGHT_CATEGORY>
    </LIGHT_DESCRIPTION>
    <LIGHT_DESCRIPTION>
        <LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
        <LIGHT_CATEGORY>UNKNOWN</LIGHT_CATEGORY>
    </LIGHT_DESCRIPTION>
    <LIGHT_DESCRIPTION>
        <LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
        <LIGHT_CATEGORY>UNKNOWN</LIGHT_CATEGORY>
    </LIGHT_DESCRIPTION>
    <LIGHT_DESCRIPTION>
        <LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
        <LIGHT_CATEGORY>17</LIGHT_CATEGORY>
    </LIGHT_DESCRIPTION>
    <LIGHT_DESCRIPTION>
        <LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
        <LIGHT_CATEGORY>UNKNOWN</LIGHT_CATEGORY>
    </LIGHT_DESCRIPTION>      
    <LIGHT_DESCRIPTION>
        <LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
        <LIGHT_CATEGORY>17</LIGHT_CATEGORY>
    </LIGHT_DESCRIPTION>
    <LIGHT_DESCRIPTION>
        <LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
        <LIGHT_CATEGORY>17</LIGHT_CATEGORY>
    </LIGHT_DESCRIPTION>
</LIGHT_DESCRIPTION_LIST>

这是我的 XSLT:

<xsl:for-each select="LIGHT_DESCRIPTION_LIST">
    <xsl:for-each select="LIGHT_DESCRIPTION">
        <xsl:if test="LIGHT_CATEGORY = '17'">
            <xsl:text>IRA</xsl:text>
        </xsl:if>
    </xsl:for-each>
</xsl:for-each>

在输出中,我有:爱尔兰共和军 爱尔兰共和军
我会:IRA(如果存在一个轻类别= 17只写一次IRA,没有重复)

无论如何,请尝试以下代码:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:key name="LD" match="LIGHT_DESCRIPTION" use="."/>
    <xsl:variable name="Light_Desc" select="//LIGHT_DESCRIPTION"/>
    <xsl:template match="LIGHT_DESCRIPTION_LIST">
        <xsl:for-each select="$Light_Desc[count(. | key('LD', .)[1]) = 1]">
            <xsl:if test="LIGHT_CATEGORY = '17'">
            <br/>
            <span style="font-family:Univers Condensed; font-size:9pt; ">
                <xsl:text>IRA</xsl:text>
            </span>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

在测试节点内容之前,必须使用密钥并消除重复项。

<xsl:key name="LD" match="//LIGHT_DESCRIPTION" use="."/>

<xsl:for-each select="LIGHT_DESCRIPTION_LIST">
    <xsl:for-each select="LIGHT_DESCRIPTION">
    <xsl:variable name="Light_Desc" select="."/>
        <xsl:for-each select="$Light_Desc[count(. | key('LD', .)[1]) = 1]">
            <xsl:if test="LIGHT_CATEGORY = '17'">
            <xsl:text>IRA</xsl:text>
            </xsl:if>
        </xsl:for-each>
    </xsl:for-each>
</xsl:for-each>

在输出中,这给出了:

爱尔兰共和军

相关内容

  • 没有找到相关文章

最新更新