XSL删除值上的元素并添加带有连接值的新元素(1,2,3 ..)

时间:2013-08-15 21:18:57

标签: xslt element

我对XSLT非常陌生,并且有助于前进。我能够使用XSL只获取错误的成功值,但是要将output.xml中显示的所有QUEID值作为列表,  我无法前进。任何帮助将不胜感激。

            XSL
            =========
            <xsl:stylesheet version="1.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:variable name="gb"/>
                <xsl:template match="node()|@*">
                    <xsl:copy>
                        <xsl:apply-templates select="node()|@*"/>
                    </xsl:copy>
                </xsl:template>
                <xsl:template match="//Entity[success='true']"/>
            </xsl:stylesheet>


            Input XML
            ==============
            <?xml version="1.0"?>
            <Entities>
                <Entity>
                    <Type/>
                    <QUEID>14077317</QUEID>
                    <ENUM>95299168</ENUM>
                    <success>false</success>
                </Entity>
                <Entity>
                    <Type/>
                    <QUEID>14077319</QUEID>
                    <ENUM>95299151</ENUM>
                    <success>false</success>
                </Entity>
                <Entity>
                    <Type/>
                    <QUEID>14077320</QUEID>
                    <ENUM>95299154</ENUM>
                    <success>true</success>
                </Entity>
                <Entity>
                    <Type/>
                    <QUEID>14077328</QUEID>
                    <ENUM>95299164</ENUM>
                    <success>false</success>
                </Entity>
                <Entity>
                    <Type/>
                    <QUEID>14077329</QUEID>
                    <ENUM>95299147</ENUM>
                    <success>true</success>
                </Entity>
            </Entities>


            Desired Output XML
            ===================
            <?xml version="1.0"?>
            <Entities>
                <Entity>
                    <Type/>
                    <QUEID>102</QUEID>
                    <ENUM>98</ENUM>
                    <success>true</success>
                </Entity>
                <Entity>
                    <Type/>
                    <QUEID>104</QUEID>
                    <ENUM>67</ENUM>
                    <success>true</success>
                </Entity>
                      <EntityList>102,104</EntityList>
            </Entities>

1 个答案:

答案 0 :(得分:1)

你需要说明它是XSLT 1.0还是2.0。在2.0中,添加模板规则

<xsl:template match="Entities">
<xsl:copy>
  <xsl:apply-templates/>
  <EntityList>
    <xsl:value-of select="//Entity[success='false']/QUEID" separator=","/>
  </EntityList>
</xsl:copy>
</xsl:template>