私は親子関係を持つ以下の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>