You are currently viewing XSLT <xsl:for-each> Element with Example. (Useful for B1if- SAP B1)
SAP Business One

XSLT Element with Example. (Useful for B1if- SAP B1)


You can extract that data from XML file using <xsl:for-each> Element of XSLT. This is also use full to get multiple records from the XML.

For example:

If you want to insert Business Partner using B1if then you need to pass XML file that contain the BP details as well as Address details. There is multiple address like billing address, shipping address, Main address etc. Here you can pass multiple row for the address with the request Body SOAP and using Xform Atom, you can get the data from the XML.

The Simple Example

XML data (Useful to insert Business Partner- SOAP Request Format):

<?xml version=”1.0″ encoding=”UTF-8″?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV=”“>






<CardName>ABC AG</CardName>


<Notes>Inserted using B1if</Notes>



<FreeText>Processing testing</FreeText>





<!– multiple such elements are allowed –>


<Street>Street 555</Street>





<AddressName2>ABC AG Main</AddressName2>

<AddressName3>Nr. XYZ</AddressName3>





<Street>Street 555</Street>





<AddressName2>ABC AG Main</AddressName2>

<AddressName3>Nr. XYZ</AddressName3>







XSLT (with for-each loop) – You can also use following template for Xform for DI API (BP insert using B1if)

<?xml version=”1.0″ encoding=”UTF-8″?>

<xsl:stylesheet version=”1.0″ xmlns:xsl=”“>

<xsl:template name=”transform”>

<BusinessPartners xmlns=””>



<xsl:value-of select=”//CardCode[text()]”></xsl:value-of>



<xsl:value-of select=”//CardName[text()]”></xsl:value-of>



<xsl:value-of select=”//CardType[text()]”></xsl:value-of>



<xsl:value-of select=”//Notes[text()]”></xsl:value-of>



<xsl:value-of select=”//FederalTaxID[text()]”></xsl:value-of>



<xsl:value-of select=”//Currency[text()]”></xsl:value-of>



<xsl:value-of select=”//FreeText[text()]”></xsl:value-of>




<BPAddresses xmlns=””>

<xsl:for-each select=”BPAddresses/Address”>

<!– multiple such elements are allowed –>


<xsl:value-of select=”//AddressName[text()]”></xsl:value-of>



<xsl:value-of select=”//Street[text()]”></xsl:value-of>



<xsl:value-of select=”//ZipCode[text()]”></xsl:value-of>



<xsl:value-of select=”//City[text()]”></xsl:value-of>



<xsl:value-of select=”//Country[text()]”></xsl:value-of>



<xsl:value-of select=”//AddressType[text()]”></xsl:value-of>



<xsl:value-of select=”//AddressName2[text()]”></xsl:value-of>



<xsl:value-of select=”//AddressName3[text()]”></xsl:value-of>



<xsl:value-of select=”//TypeOfAddress[text()]”></xsl:value-of>






The Final output:

C10021 ABC AG C Inserted using B1if 111111 CHF Processing testing Shipping Street 555 12345 XXXX XX bo_ShipTo ABC AG Main Nr. XYZ bo_ShipTo Billing Street 555 12345 XXXX XX bo_BillTo ABC AG Main Nr. XYZ bo_BillTo

This example shows that how to select the data from the XML. You can also used for testing purpose.

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

As you found this post useful...

Share this post on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?