Xml 需要通过XSLT获取不同的元素

Xml 需要通过XSLT获取不同的元素,xml,xslt,duplicates,Xml,Xslt,Duplicates,我在名为Query的元素下有一个可能重复的表元素列表,我需要获取不同的表元素(不是它的值,而是标记/元素名本身) /ShopArea/Connection/Query/*列出了包含重复项的表名 下面是XML <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="ShopArea.xslt"?> <ShopArea> <Connection name="C

我在名为Query的元素下有一个可能重复的表元素列表,我需要获取不同的表元素(不是它的值,而是标记/元素名本身)

/ShopArea/Connection/Query/*
列出了包含重复项的表名

下面是XML

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="ShopArea.xslt"?>
<ShopArea>
<Connection name="Connection1">
    <Report date="25-09-2011">

        <Query id="1">
            <TABLE1>1.1</TABLE1>
            <TABLE2>1.2</TABLE2>
            <TABLE3>1.3</TABLE3>
        </Query>
        <Query id="2">
            <TABLE21>2.1</TABLE21>
            <TABLE22>2.2</TABLE22>
            <TABLE23>2.3</TABLE23>
        </Query>
    </Report>

    <Report date="26-09-2011">
        <Query id="1">
            <TABLE1>26 1.1</TABLE1>
            <TABLE2>26 1.2</TABLE2>
            <TABLE3>26 1.3</TABLE3>
        </Query>
        <Query id="2">
            <TABLE21>26 2.1</TABLE21>
            <TABLE22>26 2.2</TABLE22>
            <TABLE23>26 2.3</TABLE23>
        </Query>
    </Report>
</Connection>
</ShopArea>

1.1
1.2
1.3
2.1
2.2
2.3
26 1.1
26 1.2
26 1.3
26 2.1
26 2.2
26 2.3


我引用了,但无法正确执行。

I.XSLT 1.0。此转换使用简单的

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:key name="kChildByName" match="Query/*"
  use="name()"/>

 <xsl:template match=
  "Query/*
       [generate-id()
       =
        generate-id(key('kChildByName', name())[1])
       ]">
     <xsl:value-of select="name()"/>
     <xsl:text>&#xA;</xsl:text>
 </xsl:template>

 <xsl:template match="text()"/>
</xsl:stylesheet>
<ShopArea>
    <Connection name="Connection1">
        <Report date="25-09-2011">
            <Query id="1">
                <TABLE1>1.1</TABLE1>
                <TABLE2>1.2</TABLE2>
                <TABLE3>1.3</TABLE3>
            </Query>
            <Query id="2">
                <TABLE21>2.1</TABLE21>
                <TABLE22>2.2</TABLE22>
                <TABLE23>2.3</TABLE23>
            </Query>
        </Report>
        <Report date="26-09-2011">
            <Query id="1">
                <TABLE1>26 1.1</TABLE1>
                <TABLE2>26 1.2</TABLE2>
                <TABLE3>26 1.3</TABLE3>
            </Query>
            <Query id="2">
                <TABLE21>26 2.1</TABLE21>
                <TABLE22>26 2.2</TABLE22>
                <TABLE23>26 2.3</TABLE23>
            </Query>
        </Report>
    </Connection>
</ShopArea>
TABLE1
TABLE2
TABLE3
TABLE21
TABLE22
TABLE23
II.XSLT2.0:此转换使用


I.XSLT 1.0。此转换使用简单的

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:key name="kChildByName" match="Query/*"
  use="name()"/>

 <xsl:template match=
  "Query/*
       [generate-id()
       =
        generate-id(key('kChildByName', name())[1])
       ]">
     <xsl:value-of select="name()"/>
     <xsl:text>&#xA;</xsl:text>
 </xsl:template>

 <xsl:template match="text()"/>
</xsl:stylesheet>
<ShopArea>
    <Connection name="Connection1">
        <Report date="25-09-2011">
            <Query id="1">
                <TABLE1>1.1</TABLE1>
                <TABLE2>1.2</TABLE2>
                <TABLE3>1.3</TABLE3>
            </Query>
            <Query id="2">
                <TABLE21>2.1</TABLE21>
                <TABLE22>2.2</TABLE22>
                <TABLE23>2.3</TABLE23>
            </Query>
        </Report>
        <Report date="26-09-2011">
            <Query id="1">
                <TABLE1>26 1.1</TABLE1>
                <TABLE2>26 1.2</TABLE2>
                <TABLE3>26 1.3</TABLE3>
            </Query>
            <Query id="2">
                <TABLE21>26 2.1</TABLE21>
                <TABLE22>26 2.2</TABLE22>
                <TABLE23>26 2.3</TABLE23>
            </Query>
        </Report>
    </Connection>
</ShopArea>
TABLE1
TABLE2
TABLE3
TABLE21
TABLE22
TABLE23
II.XSLT2.0:此转换使用



好极了!它可以工作,但是这个代码(明钦分组)看起来太复杂了。需要一段时间才能理解。非常感谢。@Arvind Singh:不客气。Muenchian分组是高效XSLT 1.0分组的事实标准。要更好地理解它,只需按照此答案第一行上的链接,这将导致Jeni Tennison的优秀Muenchian分组页面。Excellent!它是有效的,但是这个代码(明钦分组)看起来太复杂了。需要一段时间才能理解。非常感谢。@Arvind Singh:不客气。Muenchian分组是高效XSLT 1.0分组的事实标准。要更好地理解它,只需按照此答案第一行上的链接,这将导致Jeni Tennison的优秀Muenchian分组页面。