on ‎2010 Aug 24 7:05 PM
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!
Request clarification before answering.
This is my real source code,
Order (Root)
- OrderHeader (1parent field)- occur only once
- OrderDetail (1parent field)- occur only once
> ListOfItemDetail- occur only once
>> ItemDetail - occur multiple times
>>> BaseItemDetail
>>>> ItemIdentifiers
>>>>> PartNumbers
>>>>>> SellerPartNumber
>>>>>> BuyerPartNumber
>>>>>>> PartNum
>>>>>>>> PartID
>>>>>> ManufacturingPartNumber
>>>>>> PartID
- OrderSummary(1parent field)- occur only once
> --> this indicates the sub-fields under each segment.
- SellerPartNumber / BuyerPartNumber / ManufacturingPartNumber is on the same level
- ItemDetail can occur multiple times, the rest occur only once
The goal is to transfer the value of PartID under ManufacturingPartNumber field into the field PartID of BuyerPartNumber/PartNum.
Hope you can help. Thanks!
Im still debugging the code also.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
From your post I think your XML structure looks like this (ItemDetail can repeat) :
<Order>
<OrderHeader>header</OrderHeader>
<OrderDetail>
<ListOfItemDetail>
<ItemDetail>
<BaseItemDetail>
<ItemIdentifiers>
<PartNumbers>
<SellerPartNumber>spn1</SellerPartNumber>
<BuyerPartNumber>
<PartNum>
<PartID>bpn1</PartID>
</PartNum>
</BuyerPartNumber>
<ManufacturingPartNumber>mpn1</ManufacturingPartNumber>
<PartID>pn1</PartID>
</PartNumbers>
</ItemIdentifiers>
</BaseItemDetail>
</ItemDetail>
</ListOfItemDetail>
</OrderDetail>
<OrderSummary>ordsum</OrderSummary>
</Order>If so, then try this:
<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="BuyerPartNumber/PartNum/PartID">
<PartID><xsl:value-of select="../../../PartID"/></PartID>
</xsl:template>
</xsl:stylesheet>
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.