遍历XML树并使用XSL查找公共节点文本

遍历XML树并使用XSL查找公共节点文本,xml,xslt,Xml,Xslt,我希望遍历一棵树,找到公共元素文本,并能够显示在表中的文本上 <Root> <attr> <attrlabl>Attribute Label 1</attrlabl> <attrdef>Attribute Definition 1</attrdef> <attrdomv> <edom> <edomv>O</ed

我希望遍历一棵树,找到公共元素文本,并能够显示在表中的文本上

<Root>    
 <attr>
    <attrlabl>Attribute Label 1</attrlabl>
    <attrdef>Attribute Definition 1</attrdef>
    <attrdomv>
        <edom>
            <edomv>O</edomv>
            <edomd>Open</edomd>
        </edom>
        <edom>
            <edomv>C</edomv>
            <edomd>Close</edomd>
        </edom>
    </attrdomv>
 </attr>
 <attr>
    <attrlabl>Attribute Label 2</attrlabl>
    <attrdef>Attribute Definition 2</attrdef>
    <attrdomv>
        <edom>
            <edomv>O</edomv>
            <edomd>Open</edomd>
        </edom>
        <edom>
            <edomv>C</edomv>
            <edomd>Close</edomd>
        </edom>
    </attrdomv>
 </attr>
 <attr>
    <attrlabl>Attribute Label 3</attrlabl>
    <attrdef>Attribute Definition 3</attrdef>
    <attrdomv>
        <udom>
            <udomv>No display</udomv>
        </udom>
    </attrdomv>
 </attr>
 <attr>
    <attrlabl>Attribute Label 4</attrlabl>
    <attrdef>Attribute Definition 4</attrdef>
    <attrdomv>
        <edom>
            <edomv>D</edomv>
            <edomd>Different</edomd>
        </edom>
    </attrdomv>
 </attr>
</Root>

属性标签1
属性定义1
O
打开
C
接近
属性标签2
属性定义2
O
打开
C
接近
属性标签3
属性定义3
无显示
属性标签4
属性定义4
D
不同的
输出应该像这样,只显示公共元素文本。任何帮助都将不胜感激

<tr>
<td> For Attribute Label 1 and 2</td>
</tr>
<tr>
<td> Value: O </td>
<td> Description: Open </td>
</tr>
<tr>
<td> Value: C </td>
<td> Description: Close </td>

对于属性标签1和2
价值:O
描述:打开
数值:C
描述:关闭

尝试以下方法:

XSLT2.0

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

<xsl:template match="/Root">
    <table border="1">
        <xsl:for-each-group select="attr/attrdomv/edom" group-by="edomv">
            <xsl:if test="count(current-group()) > 1">
                <tr>
                    <td>
                        <xsl:value-of select="current-group()/ancestor::attr/attrlabl" separator=", "/>
                    </td>
                    <td>
                        <xsl:text>Value: </xsl:text>
                        <xsl:value-of select="current-grouping-key()"/>
                    </td>
                    <td>
                        <xsl:text>Description: </xsl:text>
                        <xsl:value-of select="current-group()[1]/edomd"/>
                    </td>
                </tr>
            </xsl:if>
        </xsl:for-each-group>
    </table>
</xsl:template>

</xsl:stylesheet>

价值:
说明:
当应用到示例输入时,结果将与您的略有不同:

<table border="1">
   <tr>
      <td>Attribute Label 1, Attribute Label 2</td>
      <td>Value: O</td>
      <td>Description: Open</td>
   </tr>
   <tr>
      <td>Attribute Label 1, Attribute Label 2</td>
      <td>Value: C</td>
      <td>Description: Close</td>
   </tr>
</table>

属性标签1,属性标签2
价值:O
描述:打开
属性标签1,属性标签2
数值:C
描述:关闭
主要是因为我认为祖先的身份只是巧合。

1。“公共”是否表示“出现多次”?——2.请注明XSLT 1.0或2.0。-3.与
相比,
有什么意义吗?1)是的2)XSLT 2.0 3)只需要在