Skip to Content
avatar image
Former Member

Idoc to resultset mapping via XSL

Hello,

I've created an xsl mapping for the transformation of a multi level hiearchy idoc to the file adapters resultset structure. The idoc has a header and multiple detail records:

Z103401 - header

Z103402 - detail

Z103403 - child of Z103402

I need to create a <row> for each of the Z103403 segments and within this row I need to include data from its parent Z103402 and header record Z103401. Below is my xsl and the only problem I'm having is selecting data from the correct Z103402 parent segment of the row's Z103403. The <xsl:apply-templates select="//Z104302"/>

statement of course fills the <row> with every iteration of Z104302 and I only want the parent of Z103403. How do I do this?

<?xml version="1.0" ?>

http://www.w3.org/1999/XSL/Transform">

<xsl:template match="*">

<xsl:for-each select="//Z103401">

<xsl:variable name="compcode">

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

</xsl:variable>

</xsl:for-each>

<ns0:GrossPayMsgType xmlns:ns0="urn:csc:xi:hr:dev2">

<xsl:for-each select="//Z103403">

<row>

<Companycode>

<xsl:copy-of select="$compcode" />

</Companycode>

<xsl:apply-templates select="//Z104302"/>

<WageType>

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

</WageType>

<Amount>

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

</Amount>

</row>

</xsl:for-each>

</ns0:GrossPayMsgType>

</xsl:template>

<xsl:template match="Z103402">

<PersonnelNumber>

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

</PersonnelNumber>

<PersonnelID>

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

</PersonnelID>

<StartDate>

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

</StartDate>

<EndDate>

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

</EndDate>

</xsl:template>

</xsl:stylesheet>

Thanks,

Dave

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Aug 24, 2004 at 04:05 PM

    After doing some more research I figured out how to select the elements from the parent node(../). Below is the xsl which takes an idoc with a multi level hiarchy and transforms to a flat resultset structure. Quite simple actually...

    <?xml version="1.0" ?>

    http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="*">

    <xsl:for-each select="//Z103401">

    <xsl:variable name="compcode">

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

    </xsl:variable>

    </xsl:for-each>

    <ns0:GrossPayMsgType xmlns:ns0="urn:csc:xi:hr:dev2">

    <xsl:for-each select="//Z103403">

    <row>

    <Companycode>

    <xsl:copy-of select="$compcode" />

    </Companycode>

    <PersonnelNumber>

    <xsl:value-of select="../PERNR" />

    </PersonnelNumber>

    <PersonnelID>

    <xsl:value-of select="../PERID" />

    </PersonnelID>

    <StartDate>

    <xsl:value-of select="../FPBEG" />

    </StartDate>

    <EndDate>

    <xsl:value-of select="../FPEND" />

    </EndDate>

    <WageType>

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

    </WageType>

    <Amount>

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

    </Amount>

    </row>

    </xsl:for-each>

    </ns0:GrossPayMsgType>

    </xsl:template>

    </xsl:stylesheet>

    Add comment
    10|10000 characters needed characters exceeded