cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

xslt code help needed

Former Member
0 Likes
566

Dear SAP experts,

Would you be able to help me in configuring the right xslt code to accomodate the looping logic?

Source Document:

School (occur only once)

- Name (can occur multiple times)

- Nickname (occur only once)

- Desired name (occur only once)

Target Document:

School

- Name

- Nickname (the value for this should be obtained from 'Desired name field')

- Desired name

I have this code, but seems not working in looping logic. (to accomodate the multiple Names):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" media-type="xml" encoding="UTF-8" indent="yes"/>

<xsl:template match="@*|node()">

<xsl:copy>

<xsl:apply-templates select="@*|node()"/>

</xsl:copy>

</xsl:template>

<xsl:template match="Order/OrderDetail/ListOfItemDetail/ItemDetail/BaseItemDetail/ItemIdentifiers/PartNumbers/BuyerPartNumber">

<BuyerPartNumber>

<PartNum>

<PartID>

<xsl:value-of select ="/Order/OrderDetail/ListOfItemDetail/ItemDetail/BaseItemDetail/ItemIdentifiers/PartNumbers/ManufacturerPartNumber/PartID"/>

</PartID>

</PartNum>

</BuyerPartNumber>

</xsl:template>

</xsl:stylesheet>

What happened is that the value was taken ONLY on the 1st line item. (1st Name occurence)

The succeeding Name field just copied the value of Nicknames from the 1st Name field.

Kindly advise how to handle the context (loop logic) in the xslt code.

Thanks!

View Entire Topic
Former Member
0 Likes

Thanks for this helpful information.

This is in consideration that,

School --> Main Header segment (occur only once)

Name --> sub-segment under School field (occur multiple times)

Nickname --> sub-segments under Name (occur only once)

Desired Name --> sub-segments under Name (occur only once)

Will the code you've provided applies?

Meanwhile, I will debug the code on my side also.

Thanks again,

Former Member
0 Likes

It should, the key is to know your current context and use relative or full xpaths depending on what you need. If your template matches on Name you can access all sub-nodes within Name using a relative xpath. Here's what I assumed your sample structure looks like followed by what the xsl will convert it to:

Source:

<DocRoot>
  <OtherStuff>
    <a>1</a>
  </OtherStuff>
  <School>
    <Name>
      <Nickname>Nickname1</Nickname>
      <DesiredName>DesiredName1</DesiredName>
    </Name>
    <Name>
      <Nickname>Nickname2</Nickname>
      <DesiredName>DesiredName2</DesiredName>
    </Name>
  </School>
</DocRoot>

Target:

<DocRoot>
  <OtherStuff>
    <a>1</a>
  </OtherStuff>
  <School>
    <Name>
      <Nickname>DesiredName1</Nickname>
      <DesiredName>DesiredName1</DesiredName>
    </Name>
    <Name>
      <Nickname>DesiredName2</Nickname>
      <DesiredName>DesiredName2</DesiredName>
    </Name>
  </School>
</DocRoot>

If you needed something different please post back what you want the results to look like.

Thanks,

-Russ