XSLT for XML过滤重复组

XSLT for XML过滤重复组,xslt,Xslt,我将输入XML作为 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <document> <item> <functionalName lang="en">Filte</functionalName> <functionalName lang="hin">test1</functionalName> <functionalName lang="

我将输入XML作为

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<document>
<item>
<functionalName lang="en">Filte</functionalName>
<functionalName lang="hin">test1</functionalName>
<functionalName lang="chi">Filters2</functionalName>
<functionalName lang="hin">Filters3</functionalName>
</item>
<item>
<functionalName lang="en">Filte</functionalName>
<functionalName lang="chi">Filters</functionalName>
<functionalName lang="en">Filters1</functionalName>
</item>

过滤
测试1
过滤器2
过滤器3
过滤
过滤器
过滤器1

下面将介绍通过XSLT解析后所需的输出 查询的末尾提到了XSLT 输出XML:

<?xml version="1.0" encoding="UTF-8"?>
<CatalogItem>
<RelationshipData>
    <Relationship>
        <RelationType>Descriptions_for_Item</RelationType>
        <RelatedItems count="3">
            <RelatedItem1 referenceKey="ITEM_DESCRIPTION-functionalName-en" />
            <RelatedItem1 referenceKey="ITEM_DESCRIPTION-functionalName-hin" />
            <RelatedItem1 referenceKey="ITEM_DESCRIPTION-functionalName-chi" />
        </RelatedItems>
    </Relationship>
</RelationshipData>
<RelationshipData>
    <Relationship>
        <RelationType>Descriptions_for_Item</RelationType>
        <RelatedItems count="2">
            <RelatedItem1 referenceKey="ITEM_DESCRIPTION-functionalName-en" />
            <RelatedItem1 referenceKey="ITEM_DESCRIPTION-functionalName-chi" />
        </RelatedItems>
    </Relationship>
</RelationshipData>

项目的描述
项目的描述

我使用的XSLT没有给我想要的响应。请帮忙

<xsl:output method="xml" indent="yes" />

<xsl:key name="functional" match="functionalName" use="@lang" />  

<xsl:template match="document"> 
    <CatalogItem>
        <xsl:for-each select="item">
            <RelationshipData>
                <Relationship>
                    <RelationType>Descriptions_for_Item</RelationType>

                    <RelatedItems>
                        <xsl:attribute name="count">
                            <xsl:value-of select="count(functionalName[generate-id(.)=generate-id(key('functional',@lang)[1])])"/>          
                        </xsl:attribute>
                        <xsl:apply-templates select="functionalName[generate-id(.)=generate-id(key('functional',@lang)[1])]"/>  
                    </RelatedItems> 
                </Relationship>
            </RelationshipData>
        </xsl:for-each>
    </CatalogItem>
</xsl:template> 


<xsl:template match="functionalName">
    <xsl:for-each value="{@lang}">  
        <xsl:variable name="language" select="../@lang" />              
        <RelatedItem1>
            <xsl:attribute name="referenceKey">
                <xsl:value-of select="concat('ITEM_DESCRIPTION','-','functionalName','-',../@lang)"/>
            </xsl:attribute>
        </RelatedItem1>
    </xsl:for-each>
</xsl:template> 


项目的描述

<xsl:key name="functional" match="functionalName" use="@lang" />
所以完整的样本是

<xsl:stylesheet 
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>

<xsl:key name="functional" match="functionalName" use="concat(generate-id(..), '|', @lang)" />  

<xsl:template match="document"> 
    <CatalogItem>
        <xsl:for-each select="item">
            <RelationshipData>
                <Relationship>
                    <RelationType>Descriptions_for_Item</RelationType>
                       <RelatedItems count="{count(functionalName[generate-id() = generate-id(key('functional', concat(generate-id(..), '|', @lang))[1])])}">
                          <xsl:apply-templates select="functionalName[generate-id() = generate-id(key('functional', concat(generate-id(..), '|', @lang))[1])]"/> 
                       </RelatedItems>
                </Relationship>
            </RelationshipData>
        </xsl:for-each>
    </CatalogItem>
</xsl:template> 


<xsl:template match="functionalName">              
        <RelatedItem1 referenceKey="{concat('ITEM_DESCRIPTION','-','functionalName','-', @lang)}"/>
</xsl:template>

</xsl:stylesheet>

项目的描述
<RelatedItems count="{count(functionalName[generate-id() = generate-id(key('functional', concat(generate-id(..), '|', @lang))[1])])}">
<xsl:apply-templates select="functionalName[generate-id() = generate-id(key('functional', concat(generate-id(..), '|', @lang))[1])]"/> 
<xsl:template match="functionalName">              
        <RelatedItem1 referenceKey="{concat('ITEM_DESCRIPTION','-','functionalName','-', @lang)}"/>
</xsl:template> 
<xsl:stylesheet 
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>

<xsl:key name="functional" match="functionalName" use="concat(generate-id(..), '|', @lang)" />  

<xsl:template match="document"> 
    <CatalogItem>
        <xsl:for-each select="item">
            <RelationshipData>
                <Relationship>
                    <RelationType>Descriptions_for_Item</RelationType>
                       <RelatedItems count="{count(functionalName[generate-id() = generate-id(key('functional', concat(generate-id(..), '|', @lang))[1])])}">
                          <xsl:apply-templates select="functionalName[generate-id() = generate-id(key('functional', concat(generate-id(..), '|', @lang))[1])]"/> 
                       </RelatedItems>
                </Relationship>
            </RelationshipData>
        </xsl:for-each>
    </CatalogItem>
</xsl:template> 


<xsl:template match="functionalName">              
        <RelatedItem1 referenceKey="{concat('ITEM_DESCRIPTION','-','functionalName','-', @lang)}"/>
</xsl:template>

</xsl:stylesheet>