cancel
Showing results for 
Search instead for 
Did you mean: 

File to IDOC - xslt problem

jakob_steen-petersen
Active Participant
0 Kudos

Hi,

I use the File content conversion to convert a flat file into xml. File looks like this:

0TopData

1HeaderData

2ItemData

2ItemData

1HeaderData

2ItemData

9End

This is convertet into an XML:

<top></top>

<header></header>

<item></item>

<item></item>

<header></header>

<item></item>

<end></end>

But i need to do an xslt who transform it to the following structure:

<top></top>

<header>

<item></item>

<item></item>

</header>

<header>

<item></item>

</header>

<end></end>

But i do not know how to do the xslt so that the items for each header are placed correctly? There are no fields in the header/item structures who binds them togheter.

/Jakob

Accepted Solutions (0)

Answers (4)

Answers (4)

jakob_steen-petersen
Active Participant
0 Kudos

Yes in the TARGET xml Header and Item are not in the same level. But in the SOURCE they are. And thats a problem as i understand it because if i use the for-each thing i will get ALL the ITEMS in All the headers right?

Correct me if i´m wrong!

/Jakob

jakob_steen-petersen
Active Participant
0 Kudos

Hi,

I think Amit is on the right track but i´m new in xslt so i might take a while to test.

Prasad: notice that the header and Item tag are on the same level!

/Jakob

former_member181955
Contributor
0 Kudos

Hi

As per you in your target structure item and header are not in the same level.Item is in the header node.

You please check what you posted.

thanks

Prasad

Former Member
0 Kudos

Hi Jacob,

You can refer to the link http://www.w3.org/TR/xslt for authentic information about XSLT.

CHEERS

Amit

former_member181955
Contributor
0 Kudos

Hi

Please do the xslt as following and please let me know if any issue is there.

<b>Source</b>

<?xml version="1.0" encoding="UTF-8"?>

<Mt_Source>

<top></top>

<header></header>

<item></item>

<item></item>

<header></header>

<item></item>

<item></item>

<end></end>

</Mt_Source>

<b>Targert</b>

<?xml version="1.0" encoding="UTF-8"?>

<Mt_Target>

<top></top>

<header>

<item></item>

<itme></itme>

</header>

<header>

<item></item>

<item></item>

</header>

<end></end>

</Mt_Target>

<b>xslt mapping</b>

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:nr1="http://www.w3.org/2001/XMLSchema-instance">

<xsl:template match="/">

<Mt_Target>

<xsl:element name="top">

<xsl:value-of select="Mt_Source/top"/>

</xsl:element>

<xsl:for-each select="Mt_Source/header>

<xsl:element name="header">

<xsl:value-of select="header"/>

<xsl:for-each select="header/item">

<xsl:element name="item">

<xsl:value-of select="item"/>

</xsl:element>

</xsl:for-each>

</xsl:element>

</xsl:for-each>

<xsl:element name="end">

<xsl:value-of select="Mt_Target/end"/>

</xsl:element>

</Mt_Target>

</xsl:template>

</xsl:transform>

Thanks

Matthew Prasad: 91-9960226467

Former Member
0 Kudos

Hello Jacob,

You can apply following steps

In the beginning look for first Header node and call a custom template to transform it.

Logic for template:

a. The template should add a header node and append all subsequent nodes to output until the next node found is not Header.

b. When the next node is Header, the already open Header node should be closed and again the template should be called with next node i.e. Header

c. When the next node is End, an End node should be added to output.

Also have a look at following blogs

/people/anish.abraham2/blog/2005/12/22/file-to-multiple-idocs-xslt-mapping

/people/pooja.pandey/blog/2005/06/27/xslt-mapping-with-java-enhancement-for-beginners

/people/prasadbabu.nemalikanti3/blog/2006/03/30/xpath-functions-in-xslt-mapping

Regards

Amit