Reputation: 53
Good day. I need an your assistance. I'm not frequent XSLT developer I developed XSLT which I expected to get output, however my XSLT not provide expected way. Could you please give me your valuable suggestions.
XML Input:
<Order>
<OrderTypes>
<SalesOrder>3000016154</SalesOrder>
<SoldToParty>1</SoldToParty>
<ItemPartner>
<PartnerTypes>
<PFunction>SH</PFunction>
<Customer>A</Customer>
<Address>
<AddressType>
<Name>Test_FinalCustomer1</Name>
<Address>Test_FinalCustomer1</Address>
</AddressType>
</Address>
</PartnerTypes>
<PartnerTypes>
<PFunction>FC</PFunction>
<Customer>B</Customer>
<Address>
<AddressType>
<Name>Test_FinalCustomer2</Name>
<Address>Test_FinalCustomer2</Address>
</AddressType>
</Address>
</PartnerTypes>
</ItemPartner>
<ItemTypes>
<Types>
<Unit>KG</Unit>
<NetAmount>5000.00</NetAmount>
<PricingElementsType>
<PrElementType>
<RateValue>2000</RateValue>
<Quantity>1</Quantity>
<Type>PR00</Type>
</PrElementType>
<PrElementType>
<RateValue>3000</RateValue>
<Quantity>2</Quantity>
<Type>PR01</Type>
</PrElementType>
</PricingElementsType>
</Types>
<Types>
<Unit>ML</Unit>
<NetAmount>6000.00</NetAmount>
<PricingElementsType>
<PrElementType>
<RateValue>4000</RateValue>
<Quantity>1</Quantity>
<Type>PR00</Type>
</PrElementType>
<PrElementType>
<RateValue>2000</RateValue>
<Quantity>2</Quantity>
<Type>PR01</Type>
</PrElementType>
</PricingElementsType>
</Types>
</ItemTypes>
</OrderTypes>
</Order>
XSLT Code
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:map="http://www.w3.org/2005/xpath-functions/map" xmlns:n0="http://sap.com/xi/SAPGlobal20/Global" exclude-result-prefixes="xs" xmlns:exsl="http://exslt.org/common" xmlns:ext="http://exslt.org/common">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Order">
<xsl:for-each select="OrderTypes">
<data>
<xsl:if test="SalesOrder">
<VBELN>
<xsl:value-of select="SalesOrder"/>
</VBELN>
</xsl:if>
<HEAD>
<xsl:if test="SalesOrder">
<VBELN>
<xsl:value-of select="SalesOrder"/>
</VBELN>
</xsl:if>
<xsl:if test="SoldToParty">
<KUNNR_AG>
<xsl:value-of select="SoldToParty"/>
</KUNNR_AG>
</xsl:if>
<xsl:for-each select="//PartnerTypes">
<xsl:if test="PFunction = 'SH'">
<xsl:if test=" Customer">
<KUNNR_SH>
<xsl:value-of select="Customer"/>
</KUNNR_SH>
</xsl:if>
<xsl:for-each select="//AddressType">
<xsl:if test="Address">
<Address>
<xsl:value-of select="Address"/>
</Address>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="//Types">
<HEAD_ENTRIES>
<xsl:if test="Unit">
<UNIT>
<xsl:value-of select="Unit"/>
</UNIT>
</xsl:if>
<xsl:if test="NetAmount">
<NET_AMOUNT>
<xsl:value-of select="NetAmount"/>
</NET_AMOUNT>
</xsl:if>
<xsl:for-each select="//PrElementType">
<xsl:if test="Type ='PR00'">
<xsl:if test="RateValue">
<RATE_VALUE>
<xsl:value-of select="RateValue"/>
</RATE_VALUE>
</xsl:if>
<xsl:if test="Quantity">
<QUANTITY>
<xsl:value-of select="Quantity"/>
</QUANTITY>
</xsl:if>
</xsl:if>
</xsl:for-each>
</HEAD_ENTRIES>
</xsl:for-each>
</HEAD>
</data>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Expected Output:
<data xmlns:java="http://xml.apache.org/xslt/java"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:n0="http://sap.com/xi/SAPGlobal20/Global"
xmlns:exsl="http://exslt.org/common"
xmlns:ext="http://exslt.org/common">
<VBELN>3000016154</VBELN>
<HEAD>
<VBELN>3000016154</VBELN>
<KUNNR_AG>1</KUNNR_AG>
<KUNNR_SH>A</KUNNR_SH>
<Address>Test_FinalCustomer1</Address>
<HEAD_ENTRIES>
<UNIT>KG</UNIT>
<NET_AMOUNT>5000.00</NET_AMOUNT>
<RATE_VALUE>2000</RATE_VALUE>
<QUANTITY>1</QUANTITY>
</HEAD_ENTRIES>
<HEAD_ENTRIES>
<UNIT>ML</UNIT>
<NET_AMOUNT>6000.00</NET_AMOUNT>
<RATE_VALUE>4000</RATE_VALUE>
<QUANTITY>1</QUANTITY>
</HEAD_ENTRIES>
</HEAD>
</data>
Could you please give me your valuable suggestions. Thank you
With Best Regards, Sateesh N
Upvotes: 1
Views: 36
Reputation: 53
as Input suggested by Siebe Jongebloed, my problem has been resolved to use the context add a . in front of them: .//
Thank you very much for this community.
Upvotes: 1