我对 XSLT 非常陌生,需要一些帮助才能继续前进。我能够创建一个 XSL2.0 来仅获取错误的成功值并删除重复项,但是将 UNIQUE QUEID 值作为单个列表获取,如 output.xml 中所示,这是我想要的,但我得到了包括重复项在内的所有值(100,100,100,101,103)。任何帮助将不胜感激。
输入 XML
<?xml version="1.0"?>
<Entities>
<Entity>
<Type/>
<QUEID>100</QUEID>
<ENTY>95</ENTY>
<success>false</success>
</Entity>
<Entity>
<Type/>
<QUEID>100</QUEID>
<ENTY>898</ENTY>
<success>false</success>
</Entity>
<Entity>
<Type/>
<QUEID>100</QUEID>
<ENTY>454</ENTY>
<success>false</success>
</Entity>
<Entity>
<Type/>
<QUEID>101</QUEID>
<ENTY>45</ENTY>
<success>false</success>
</Entity>
<Entity>
<Type/>
<QUEID>102</QUEID>
<ENTY>454</ENTY>
<success>true</success>
</Entity>
<Entity>
<Type/>
<QUEID>103</QUEID>
<ENTY>56</ENTY>
<success>true</success>
</Entity>
<Entity>
<Type/>
<QUEID>103</QUEID>
<ENTY>656</ENTY>
<success>false</success>
</Entity>
<Entity>
<Type/>
<QUEID>104</QUEID>
<ENTY>234</ENTY>
<success>true</success>
</Entity>
</Entities>
使用 XSL
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//Entity[success='true']"/>
<xsl:template match="/*">
<Entities>
<xsl:for-each-group select="Entity" group-by="QUEID">
<xsl:apply-templates select="."/>
</xsl:for-each-group>
<EntityList>
<xsl:value-of select="//Entity[success='false']/QUEID" separator=","/>
</EntityList>
</Entities>
</xsl:template>
</xsl:stylesheet>
所需的输出 XML
<?xml version="1.0" encoding="UTF-8"?>
<Entities>
<Entity>
<Type/>
<QUEID>100</QUEID>
<ENTY>95</ENTY>
<success>false</success>
</Entity>
<Entity>
<Type/>
<QUEID>101</QUEID>
<ENTY>45</ENTY>
<success>false</success>
</Entity>
<Entity>
<Type/>
<QUEID>103</QUEID>
<ENTY>56</ENTY>
<success>false</success>
</Entity>
<EntityList>100,101,103</EntityList>
</Entities>