我有一个非常扁平的 XML 结构,我需要将其重新排序为分类的部分,而且,在我的一生中,我无法弄清楚如何在 XSLT 中做到这一点(我绝不是专家。)
基本上,原始 XML 看起来有点像:
<things>
<thing>
<value>one</value>
<type>a</type>
</thing>
<thing>
<value>two</value>
<type>b</type>
</thing>
<thing>
<value>thee</value>
<type>b</type>
</thing>
<thing>
<value>four</value>
<type>a</type>
</thing>
<thing>
<value>five</value>
<type>d</type>
</thing>
</things>
我需要输出如下内容:
<data>
<a-things>
<a>one</a>
<a>four</a>
</a-things>
<b-things>
<b>two</b>
<b>three</b>
</b-things>
<d-things>
<d>five</d>
</d-things>
</data>
<c-things>
请注意,如果没有任何元素,我无法输出<c>
,但我确实提前知道完整的类型列表是什么,而且它相当短,因此每种类型的手动编码模板绝对是可能的。感觉就像我可能可以一起破解一些东西<xsl:if>
,<xsl:for-each>
但也感觉必须有一个更......'模板'的方式来做到这一点。任何人都可以帮忙吗?
干杯。