cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT Help Request - Building Hierarchy

Former Member
0 Kudos

Hi everyone,

We are receiving a file that has the following structure, where fields that start with H are header fields, and fields that start with D are detail fields (like a header and line items in an FI posting).

H1, H2, H3, D1, D2, D3, D4, D5

On the first line of the FI posting, the H and the D fields are populated (i.e. contains the header information, and the first line item information). Then on the next lines, the H fields are all blank, and the D fields are populated. So like this:

H1, H2, H3, D1, D2, D3, D4 (for line item 1)
 , , ,D1, D2, D3, D4 (for line item 2)

The file can also have more than 1 FI posting (i.e. more than 1 Header):

H1, H2, H3, D1, D2, D3, D4 (for line item 1)
 , , ,D1, D2, D3, D4 (for line item 2)
H1, H2, H3, D1, D2, D3, D4 (for line item 1)
 , , ,D1, D2, D3, D4 (for line item 2)

We are trying to map this into a FIDCC1 idoc posting, which looks like this:

<FIDCCP01>
  <IDOC>
    <Header>
      <H1></H1>
      <H2></H2>
      <H3></H3>
      <Item><D1></D1><D2></D2><D3></D3><D4></D4></Item>
      <Item><D1></D1><D2></D2><D3></D3><D4></D4></Item>
    </Header>
  </IDOC>
  <IDOC>
    <Header>
      <H1></H1>
      <H2></H2>
      <H3></H3>
      <Item><D1></D1><D2></D2><D3></D3><D4></D4></Item>
      <Item><D1></D1><D2></D2><D3></D3><D4></D4></Item>
    </Header>
  </IDOC>
</FIDCCP01>     

We can't make this work alone in the concent conversion, so was thinking that this could be done in XSLT. We have created a data type that contains the fill H and D fields and are taking this into XI no problems, but we are having problems putting it into the hierarchy. Any help is greatly appreciated.

Thanks

Peter

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Here is the input file, top line being the field breakdown


12222333333334444566666666666666667777777777777777
1FB0104052007ARP 20000000026590.000000000000000.00
/////////////////20000000098765.000000000000000.00
1FB0104052007USD 20000000012345.000000000000000.00
/////////////////20000000054321.000000000000000.00

Field 1, when it is a "1", is the start of the header line. Field 5 will always be a "2", and is the start of the detail line. Also all null fields are populated with a slash.

My idea was to take this in all on 1 line where the structure contains both the header and the detail fields, because I wasn't sure if content conversion could do what I wanted. When I do that, here is the result:

<?xml version="1.0" encoding="utf-8"?>
<ns:IFS_MT xmlns:ns="http://xx.com/xi/fin/gl/iams/ifs">
	<Detail>
		<STYPE1>1</STYPE1>
		<TCODE>FB01</TCODE>
		<BLDAT>04052007</BLDAT>
		<WAERS>ARP</WAERS>
		<STYPE2>2</STYPE2>
		<WRBTR>0000000026590.00</WRBTR>
		<DMBE2>0000000000000.00</DMBE2>
	</Detail>
	<Detail>
		<STYPE1>/</STYPE1>
		<TCODE>////</TCODE>
		<BLDAT>////////</BLDAT>
		<WAERS>////</WAERS>
		<STYPE2>2</STYPE2>
		<WRBTR>0000000098765.00</WRBTR>
		<DMBE2>0000000000000.00</DMBE2>
	</Detail>
	<Detail>
		<STYPE1>1</STYPE1>
		<TCODE>FB01</TCODE>
		<BLDAT>04052007</BLDAT>
		<WAERS>USD</WAERS>
		<STYPE2>2</STYPE2>
		<WRBTR>0000000012345.00</WRBTR>
		<DMBE2>0000000000000.00</DMBE2>
	</Detail>
	<Detail>
		<STYPE1>/</STYPE1>
		<TCODE>////</TCODE>
		<BLDAT>////////</BLDAT>
		<WAERS>////</WAERS>
		<STYPE2>2</STYPE2>
		<WRBTR>0000000054321.00</WRBTR>
		<DMBE2>0000000000000.00</DMBE2>
	</Detail>	
</ns:IFS_MT>

I am open to changing the file content conversion if there is a better way!

The desired result is:

<FIDCCP01>
	<IDOC>
		<E1FIKPF>
			<TCODE>FB01</TDOCE>
			<BLDAT>04052007</BLDAT>
			<WAERS>ARP</WAERS>
			<E1FISEG>
				<WRBTR>0000000026590.00</WRBTR>
				<DMBE2>0000000000000.00</DMBE2>
			</E1FISEG>
			<E1FISEG>
				<WRBTR>0000000098765.00</WRBTR>
				<DMBE2>0000000000000.00</DMBE2>
			</E1FISEG>
		</E1FIKPF>
	</IDOC>
	<IDOC>
		<E1FIKPF>
			<TCODE>FB01</TDOCE>
			<BLDAT>04052007</BLDAT>
			<WAERS>USD</WAERS>
			<E1FISEG>
				<WRBTR>0000000012345.00</WRBTR>
				<DMBE2>0000000000000.00</DMBE2>
			</E1FISEG>
			<E1FISEG>
				<WRBTR>0000000054321.00</WRBTR>
				<DMBE2>0000000000000.00</DMBE2>
			</E1FISEG>
		</E1FIKPF>
	</IDOC>
</FIDCCP01>

Thanks again!

Peter

udo_martens
Active Contributor
0 Kudos

Hi Peter,

i dont see any rule, how to merge the structure E1FISEG into the right idoc/E1FISEG. We have field in the source, but if there are only 4 slashes inside, i have no rule. I can help you with XSL, but not with the file adapter.

Regards,

Udo

Former Member
0 Kudos

The rule is to loop through the structure. At each header line, create the eifikpf segment, plus the first e1fiseg as the header line also contains the first detail line. Each detail line populates an e1fiseg under the current e1fikpf. Then when I hit the next header line, close off the first header and start all over.

Former Member
0 Kudos

Hi Peter,

don't know if it is still relevant... The following XSLT should solve your issue:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <FIDCCP01>
      <xsl:for-each select="//Detail">
        <!--Main Loop-->
        <xsl:choose>
          <xsl:when test="./STYPE1!='/'">
            <!--Process the header-->
            <IDOC>
              <E1FIKPF>
                <TCODE>
                  <xsl:value-of select="./TCODE"/>
                </TCODE>
                <BLDAT>
                  <xsl:value-of select="./BLDAT"/>
                </BLDAT>
                <WAERS>
                  <xsl:value-of select="./WAERS"/>
                </WAERS>
                <E1FISEG>
                  <WRBTR>
                    <xsl:value-of select="./WRBTR"/>
                  </WRBTR>
                  <DMBE2>
                    <xsl:value-of select="./DMBE2"/>
                  </DMBE2>
                </E1FISEG>
                <xsl:call-template name="findCorrespondingItemsRecursively"/>
              </E1FIKPF>
            </IDOC>
          </xsl:when>
        </xsl:choose>
      </xsl:for-each>
    </FIDCCP01>
  </xsl:template>

  <xsl:template name="findCorrespondingItemsRecursively">
    <xsl:choose>
      <xsl:when test="./following-sibling::*[position()=1]/STYPE1='/'">
        <xsl:for-each select="./following-sibling::*[position()=1]">
          <E1FISEG>
            <WRBTR>
              <xsl:value-of select="./WRBTR"/>
            </WRBTR>
            <DMBE2>
              <xsl:value-of select="./DMBE2"/>
            </DMBE2>
          </E1FISEG>
          <xsl:call-template name="findCorrespondingItemsRecursively"/>
        </xsl:for-each>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

Regards,

Helmut

<i>P.S.: If it helps you, please reward some points ;-)</i>

Answers (4)

Answers (4)

Former Member
0 Kudos

Helmut,

Exactly what I was looking for!!!! Thanks so much. Points awarded.

Peter

Former Member
0 Kudos

Here is the input file, top line being the field breakdown


12222333333334444566666666666666667777777777777777
1FB0104052007ARP 20000000026590.000000000000000.00
/////////////////20000000098765.000000000000000.00
1FB0104052007USD 20000000012345.000000000000000.00
/////////////////20000000054321.000000000000000.00

Field 1, when it is a "1", is the start of the header line. Field 5 will always be a "2", and is the start of the detail line. Also all null fields are populated with a slash.

My idea was to take this in all on 1 line where the structure contains both the header and the detail fields, because I wasn't sure if content conversion could do what I wanted. When I do that, here is the result:

<?xml version="1.0" encoding="utf-8"?>
<ns:IFS_MT xmlns:ns="http://xx.com/xi/fin/gl/iams/ifs">
 <Detail>
  <STYPE1>1</STYPE1>
  <TCODE>FB01</TCODE>
  <BLDAT>04052007</BLDAT>
  <WAERS>ARP</WAERS>
  <STYPE2>2</STYPE2>
  <WRBTR>0000000026590.00</WRBTR>
  <DMBE2>0000000000000.00</DMBE2>
 </Detail>
 <Detail>
  <STYPE1>/</STYPE1>
  <TCODE>////</TCODE>
  <BLDAT>////////</BLDAT>
  <WAERS>////</WAERS>
  <STYPE2>2</STYPE2>
  <WRBTR>0000000098765.00</WRBTR>
  <DMBE2>0000000000000.00</DMBE2>
 </Detail>
 <Detail>
  <STYPE1>1</STYPE1>
  <TCODE>FB01</TCODE>
  <BLDAT>04052007</BLDAT>
  <WAERS>USD</WAERS>
  <STYPE2>2</STYPE2>
  <WRBTR>0000000012345.00</WRBTR>
  <DMBE2>0000000000000.00</DMBE2>
 </Detail>
 <Detail>
  <STYPE1>/</STYPE1>
  <TCODE>////</TCODE>
  <BLDAT>////////</BLDAT>
  <WAERS>////</WAERS>
  <STYPE2>2</STYPE2>
  <WRBTR>0000000054321.00</WRBTR>
  <DMBE2>0000000000000.00</DMBE2>
 </Detail> 
</ns:IFS_MT>

I am open to changing the file content conversion if there is a better way!

The desired result is:

<FIDCCP01>
 <IDOC>
  <E1FIKPF>
   <TCODE>FB01</TDOCE>
   <BLDAT>04052007</BLDAT>
   <WAERS>ARP</WAERS>
   <E1FISEG>
    <WRBTR>0000000026590.00</WRBTR>
    <DMBE2>0000000000000.00</DMBE2>
   </E1FISEG>
   <E1FISEG>
    <WRBTR>0000000098765.00</WRBTR>
    <DMBE2>0000000000000.00</DMBE2>
   </E1FISEG>
  </E1FIKPF>
 </IDOC>
 <IDOC>
  <E1FIKPF>
   <TCODE>FB01</TDOCE>
   <BLDAT>04052007</BLDAT>
   <WAERS>USD</WAERS>
   <E1FISEG>
    <WRBTR>0000000012345.00</WRBTR>
    <DMBE2>0000000000000.00</DMBE2>
   </E1FISEG>
   <E1FISEG>
    <WRBTR>0000000054321.00</WRBTR>
    <DMBE2>0000000000000.00</DMBE2>
   </E1FISEG>
  </E1FIKPF>
 </IDOC>
</FIDCCP01>

Thanks again!

Peter

udo_martens
Active Contributor
0 Kudos

Hi Peter,

can you provide a <b>simple</b> example

- source XML

- target: the result, what you like to have

Regards,

Udo

Former Member
0 Kudos

Once you get it into the data type in XI, you will have to have two iterations...one for the header and then one inside the first one for teh item. This will help you acieve the required output. If you can show us the source structure, then that might of much better help in looking at your problem.