Tuesday, April 21, 2009

SAP mapping and XSLT fun




      If you are on a BizTalk , SAP project , Your XSLT skills can come real handy .
      For e.g. here I needed to set a flag to true based on the existence of value in a  node. Normally this is  easy but in this case that node happens to be in a repeatable group node which can occur n number of times where n is unknown .

      It would be a mapping nightmare or a custom Xml manipulation if not for XSLT

      <xsl:for-each select="//*[local-name()='Receive' and namespace-uri()='http://Idoc/3/DEBMAS06//700/Receive']/*[local-name()='idocData' and namespace-uri()='http://Idoc/3/DEBMAS06//700/Receive']/*[local-name()='E2KNA1M005GRP' and namespace-uri()='http://Idoc/3/DEBMAS06//700']/*[local-name()='E2KNVVM007GRP' and namespace-uri()='http://Idoc/3/DEBMAS06//700']/*[local-name()='E2KNVPM002' and namespace-uri()='http://Idoc/3/DEBMAS06//700']/*[local-name()='PARVW' and namespace-uri()='http://Idoc/3/DEBMAS06//700']">

      <xsl:variable name="nodeType"><xsl:value-of select="."/></xsl:variable>
      <xsl:if test="$nodeType ='WE'">

      <xsl:element name="shipToFlag">
      Y
      </xsl:element>
      </xsl:if>
      </xsl:for-each>