我有以下具有父子关系的 XML
<EntityList>
<item>
<itemType>Parent</itemType>
<itemInfo>
<itemId>Parent1</itemId>
</itemInfo>
<childList>
<item>
<itemType>Case</itemType>
<itemInfo>
<itemId>Case1</itemId>
</itemInfo>
<childList>
<itemGroup>
<itemType>Product</itemType>
<groupItem>
<groupItemInfo>
<itemId>Product1.0</itemId>
</groupItemInfo>
<groupItemInfo>
<itemId>Product1.1</itemId>
</groupItemInfo>
</groupItem>
</itemGroup>
</childList>
</item>
<item>
<itemType>Case</itemType>
<itemInfo>
<itemId>Case2</itemId>
</itemInfo>
<childList>
<itemGroup>
<itemType>Product</itemType>
<groupItem>
<groupItemInfo>
<itemId>Product2.0</itemId>
</groupItemInfo>
<groupItemInfo>
<itemId>Product2.1</itemId>
</groupItemInfo>
</groupItem>
</itemGroup>
</childList>
</item>
<item>
<itemType>Case</itemType>
<itemInfo>
<itemId>Case3</itemId>
</itemInfo>
<childList>
<itemGroup>
<itemType>Product</itemType>
<groupItem>
<groupItemInfo>
<itemId>Product3.0</itemId>
</groupItemInfo>
<groupItemInfo>
<itemId>Product3.1</itemId>
</groupItemInfo>
</groupItem>
<!-- -->
</itemGroup>
</childList>
</item>
</childList>
</item>
</EntityList>
我需要得到这样的输出
<?xml version="1.0" encoding="UTF-8"?>
<Body>
<EntityList>
<Event>
<parentID>Parent1</parentID>
<child>
<name>Case1</name>
<name>Case2</name>
<name>Case3</name>
</child>
</Event>
<Event>
<parentID>Case1</parentID>
<child>
<name>product1.0</name>
<name>product1.1</name>
</child>
</Event>
<Event>
<parentID>Case2</parentID>
<child>
<name>product2.0</name>
<name>product2.1</name>
</child>
</Event>
<Event>
<parentID>Case3</parentID>
<child>
<name>product3.0</name>
<name>product3.1</name>
</child>
</Event>
</EntityList>
</Body>
通过使用这个 xslt,我能够获取 parentID 并获取相应 parentID 的孩子对我来说有点棘手。这意味着它必须递归调用
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:gs1ushc="http://epcis.gs1us.org/hc/ns" >
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<Body>
<EntityList>
<xsl:for-each select="//itemAggr">
<Event>
<xsl:if test="//childList">
<parentID><xsl:value-of select=".//itemId" /></parentID>
<child>
????
</child>
</xsl:if>
</Event>
</xsl:for-each>
</EntityList>
</Body>
</xsl:template>
</xsl:stylesheet>