我有几个包含数据的文件,我想将一些节点分组并制作一个文件。我只给了2个样本文件,但可能很多。输入文件在包含(list.xml)的xml文件中列出。
基本上,分组应该根据每个文件的内容进行,每个文件都应该列为该特定功能区的节点。
这可能与XSLT有关吗?也许有多个转型?
文件列表:list.xml
<?xml version="1.0" encoding="UTF-8"?>
<index xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="xml/models/1c8dca64-8b40-4e58-8581-5104f5ca3f3e.xml"/>
<xi:include href="xml/models/7f10e39d-ca8c-4c17-9a0f-2dcbceaaed51.xml"/>
<xi:include href="xml/models/2d90b9b4-793c-4d8b-9e06-0a93dfa738a2.xml"/>
<xi:include href="xml/models/4ee7085e-8241-4dae-a095-38ede5fd7fb0.xml"/>
</index>
输入文件01:1c8dca64-8b40-4e58-8581-5104f5ca3f3e.xml
<model>
<contains>
<vertex>
<functionalarea>Supply Chain</functionalarea>
<breakdowns>
<model>34c1e701-5a70-4493-b877-38624348947c</model>
</breakdowns>
</vertex>
<vertex>
<functionalarea>Supply Chain</functionalarea>
<breakdowns>
<model>25a39e71-aa59-4f63-9c09-8cc4e36bae72</model>
</breakdowns>
</vertex>
<vertex>
<functionalarea>Planning</functionalarea>
<breakdowns>
<model>45c0d6c3-a910-4050-b10e-f17eb7276c44</model>
</breakdowns>
</vertex>
</contains>
</model>
输入文件02:7f10e39d-ca8c-4c17-9a0f-2dcbceaaed51.xml
<model>
<contains>
<vertex>
<functionalarea>Supply Chain</functionalarea>
<breakdowns>
<model>58a77718-1e95-408b-a6ae-f185348ec310</model>
</breakdowns>
</vertex>
<vertex>
<functionalarea>Planning</functionalarea>
<breakdowns>
<model>87767baa-bab9-46dd-80d8-a0d0c3993429</model>
</breakdowns>
</vertex>
<vertex>
<functionalarea>Execution</functionalarea>
<breakdowns>
<model>f21aef69-9772-49bd-b6c1-4f3e55fc3887</model>
</breakdowns>
</vertex>
</contains>
</model>
必需输出
<tree>
<node>
<name>Supply Chain</name>
<children>
<child>34c1e701-5a70-4493-b877-38624348947c</child>
<child>25a39e71-aa59-4f63-9c09-8cc4e36bae72</child>
<child>58a77718-1e95-408b-a6ae-f185348ec310</child>
</children>
</node>
<node>
<name>Planning</name>
<children>
<child>45c0d6c3-a910-4050-b10e-f17eb7276c44</child>
<child>87767baa-bab9-46dd-80d8-a0d0c3993429</child>
</children>
</node>
<node>
<name>Execution</name>
<children>
<child>f21aef69-9772-49bd-b6c1-4f3e55fc3887</child>
</children>
</node>
</tree>
答案 0 :(得分:1)
首先将变量$ models绑定到模型元素集,您可以通过多种方式进行,例如
<xsl:variable name="models" select="//@href/document(.)/*"/>
然后进行分组:
<xsl:for-each-group select="$models/*/vertex" group-by="functionalarea">
<node>
<name><xsl:value-of select="current-grouping-key()"/></name>
<children>
<xsl:for-each select="current-group()">
<child><xsl:value-of select=".//model"/></child>
</xsl:for-each>
</children>
</node>
</xsl:for-each-group>