更新
我有一个xml,我想过滤包含'TYPE'的字符串,如果'TYPE'后面的字符串是重复的,也不会添加。我有这个我的xml:
<?xml version="1.0" encoding="UTF-8"?>
<INSERT>
<GROUP>,TEST,015182053980,TYPE,Car</GROUP>
<GROUP>,TEST,015182053980,DATE,2016</GROUP>
<GROUP>,ITEM,015182053997,ITEM,60200002,,STANDARD,061</GROUP>
<GROUP>,TEST,015182053997,TYPE,Car</GROUP>
<GROUP>,TEST,015182053997,DATE,2017</GROUP>
<GROUP>,TEST,015182054154,ITEM,60200002,,STANDARD,061</GROUP>
<GROUP>,TEST,015182054154,TYPE,Truck</GROUP>
<GROUP>,TEST,015182054154,DATE,2018</GROUP>
<GROUP>,TEST,015182054161,ITEM,60200002,,STANDARD,061</GROUP>
<GROUP>,TEST,015182054161,TYPE,Truck</GROUP>
<GROUP>,TEST,015182054161,DATE,2016</GROUP>
<GROUP>,TEST,015182054178,ITEM,60200002,,STANDARD,061</GROUP>
<GROUP>,TEST,015182054178,TYPE,Truck</GROUP>
<GROUP>,TEST,015182054178,DATE,2017</GROUP>
<GROUP>,TEST,015182054215,ITEM,60200002,,STANDARD,061</GROUP>
<GROUP>,TEST,015182054215,TYPE,Motorcycle</GROUP>
<GROUP>,TEST,015182054215,DATE,2018</GROUP>
<GROUP>,TEST,015182054222,ITEM,60200002,,STANDARD,061</GROUP>
<GROUP>,TEST,015182054222,TYPE,Motorcycle</GROUP>
<GROUP>,TEST,015182054222,DATE,2016</GROUP>
</INSERT>
我想要一个看起来像的xml:
<?xml version="1.0" encoding="UTF-8"?>
<Brand>
<Vehicle>Car</Vehicle>
</Brand>
<Brand>
<Vehicle>Truck</Vehicle>
</Brand>
<Brand>
<Vehicle>Motorcycle</Vehicle>
</Brand>
现在,我的xsl看起来像:
<xsl:template match= "GROUP">
<xsl:if test="contains(., 'TYPE')">
<TEST>
<Brand>
<Vehicle><xsl:value-of select="substring-after(.,'TYPE,')"/></Vehicle>
</Brand>
</TEST>
</xsl:if>
</xsl:template>
我当前的输出:
<?xml version="1.0" encoding="UTF-8"?>
<Brand>
<Vehicle>Car</Vehicle>
</Brand>
<Brand>
<Brand>
<Vehicle>Car</Vehicle>
</Brand>
<Brand>
<Vehicle>Truck</Vehicle>
</Brand>
<Brand>
<Brand>
<Vehicle>Truck</Vehicle>
</Brand>
<Brand>
<Brand>
<Vehicle>Truck</Vehicle>
</Brand>
<Brand>
<Vehicle>Motorcycle</Vehicle>
</Brand>
<Brand>
<Vehicle>Motorcycle</Vehicle>
</Brand>
现在,我使用'TYPE'获得所有行,我不知道如何更新此
答案 0 :(得分:0)
在使用XSLT 2.0时,可以在此处使用xsl:for-each-group
。
试试这个XSTL
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="INSERT">
<Brands>
<xsl:for-each-group select="GROUP[contains(., ',TYPE,')]" group-by="substring-after(., ',TYPE,')">
<Brand>
<Vehicle>
<xsl:value-of select="current-grouping-key()" />
</Vehicle>
</Brand>
</xsl:for-each-group>
</Brands>
</xsl:template>
</xsl:stylesheet>