親と子の情報を含む xml データを含むフラット ファイルがあり、変換するには xslt が必要です
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<CRStructure>
<objid>CA0D2594-183B-4E80-B2CA-4F915A1E2D32</objid>
<cr_id>87</cr_id>
<cr_parent>14</cr_parent>
</CRStructure>
<CRStructure>
<objid>23BD80FA-7ACE-4111-9607-8AC0857868AF</objid>
<cr_id>172</cr_id>
<cr_parent>128</cr_parent>
</CRStructure>
<CRStructure>
<objid>E381DE99-AD82-428E-A82B-63EB965BA2F4</objid>
<cr_id>247</cr_id>
<cr_parent>138</cr_parent>
</CRStructure>
<CRStructure> ............
に
<CR xmlns="http://ait.com/cr/">
<CRItems>
<CRItem ObjectId="69230491-BCB8-4CD5-9FC3-2113FFE832EC">
<CrId>1</CrId>
<CRItems>
<CRItem ObjectId="2D425940-B3B1-432E-BDA4-6778C9AE8391">
<CrId>2</CrId>
<CRItems>
<CRItem ObjectId="3F2DF482-0485-42C9-A1D2-FCFE0EF6B4E3">
<CrId>22</CrId>
</CRItem> .........
階層構造は常に 3 つのレベルであり、誰でも正しい方向に向けることができます。
編集
これを試してみましたが、うまくいくようです、
<xsl:template match="//NewDataSet">
<CR>
<CRItems>
<xsl:for-each select="CRStructure[cr_parent='0']">
<CRItem>
<xsl:attribute name="ObjectId">
<xsl:value-of select="objid" />
</xsl:attribute>
<CRItems>
<xsl:variable name="cridequ" select="cr_id" />
<xsl:for-each select="//NewDataSet/CRStructure[cr_parent=$cridequ]">
<CRItem>
<xsl:attribute name="ObjectId">
<xsl:value-of select="objid" />
</xsl:attribute>
<CRItems>
<xsl:variable name="cridsub" select="cr_id" />
<xsl:for-each select="//NewDataSet/CRStructure[cr_parent=$cridsub]">
<CRItem>
<xsl:attribute name="ObjectId">
<xsl:value-of select="objid" />
</xsl:attribute>
</CRItem>
</xsl:for-each>
</CRItems>
</CRItem>
</xsl:for-each>
</CRItems>
</CRItem>
</xsl:for-each>
</CRItems>
</CR>
</xsl:template>
これが正しい解決方法であるかどうかはわかりません。私が見つけたほとんどの提案は、いくつかの組み合わせを使用することです <xsl:template match....
が、これを行う方法がわかりません