Tricky XSLT
Posted: Thu Dec 21, 2006 8:42 pm
Hello all,
here is the sample structure of the import file:
So, as you see, DocumentHeader is 1:1, ItemHeader is 1:1 and ItemDetail is 1:n cardinality. The problem is that ItemHeader and ItemDetail are on the same level in the structure, and I need transformation to structure like this:
Following transformation does not work because (of course) for each ItemHeader it reads all ItemDetail in the parrent node:
Does anybody has idea how to do that?
Thanks in advance!
Best regards,
Ivan
here is the sample structure of the import file:
Code: Select all
MT_PO
DT_PO
DocumentHeader
ItemHeader
ItemDetail
DT_PO
DocumentHeader
ItemHeader
ItemDetail
ItemDetail
ItemHeader
ItemDetail
Code: Select all
MT_PO
DT_PO
DocumentHeader
Items
Item
ItemHeader
ItemDetail
DT_PO
DocumentHeader
Items
Item
ItemHeader
ItemDetail
ItemDetail
Item
ItemHeader
ItemDetail[/quote]
Following transformation does not work because (of course) for each ItemHeader it reads all ItemDetail in the parrent node:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<MT_PO>
<xsl:for-each select="MT_PO/DT_PO">
<DT_PO>
<xsl:copy-of select="DocumentHeader"/>
<Items>
<xsl:for-each select="ItemHeader">
<Item>
<xsl:copy-of select="."/>
<xsl:for-each select="../ItemDetail">
<xsl:copy-of select="."/>
</xsl:for-each>
</Item>
</xsl:for-each>
</Items>
</DT_PO>
</xsl:for-each>
</MT_PO>
</xsl:template>
</xsl:stylesheet>
Thanks in advance!
Best regards,
Ivan