on 04-17-2013 6:32 PM
Hi
I have a file that produces a flat xml as below
01 header => invoice 1
02 vendor data
03 vendor bank data
04 gl line data
01 header => invoice 2
and so on.
I am struggling with creating an xsl template that will convert the above xml into a parent-child relationship as below
01 header
===> 02 vendor data
===> 03 vendor bank data
===> 04 gl line data
01 header
Basically I want to insert all 02,03,04 nodes that follow a 01 node as children of the 01 node, until the next 01 node, and so on till the end of file.
Please can experts provide me the appropriate xsl template to process the file as desired.
Hi Gary,
can you send your source XML so that it is easy to understand.
Regards,
Sreeni.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gary,
Firstly you should use the File Adapter with Content Conversion to parse the lines in your file into a structure like this:
<Recordset>
<Record>
<RecordType>01</RecordType> <-- This is the header
<Field1>Foo</Field1>
<FieldN>Foo</FieldN>
</Record>
<Record>
<RecordType>02</RecordType> <-- This is the vendor data
<Field1>Foo</Field1>
<FieldN>Foo</FieldN>
</Record>
etc
</Recordset>
Your XSL would then need to process each RecordType in the correct sequence to produce your nesting. Using XPath Axes like below would work however it assumes that you have exactly 3 RecordTypes in-between the Header record:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Document>
<xsl:for-each select="//Record[RecordType='01']">
<Header>
<xsl:for-each select="following-sibling::*[RecordType!='01']">
<xsl:if test="position() <= '3'">
<xsl:choose>
<xsl:when test="RecordType = '02'">
<Vendor><xsl:value-of select="./FieldB"/></Vendor>
</xsl:when>
<xsl:when test="RecordType = '03'">
<VendorBank><xsl:value-of select="./FieldC"/></VendorBank>
</xsl:when>
<xsl:when test="RecordType = '04'">
<GL><xsl:value-of select="./FieldC"/></GL>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</Header>
</xsl:for-each>
</Document>
</xsl:template>
</xsl:stylesheet>
Hope this helps you.
Nick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.