BizTalk inline XSLT in mapping

96 views Asked by At

Input schema have field . Based on the this node I need to generate one destination node. Destination is single schema. If partycode is Agent I want destination node with value of Fname.

If partycode is not agent I want destination node without any value. unbounded in the schema also unbound but agent value will one in only onetime only one section. In destination is not unbounded

Scenario 1 Inputschema

    <ns0:Schema xmlns:ns0="urn:Test:esb:one:services:create:rq:1.0">
       <Participants>
        <ParticipantDetails>
          <Participant>
            <ParticipantRoleIs>
              <ParticipantRole  Value="" />
            </ParticipantRoleIs>
            <FirstName>FirstName_0</FirstName>
          </Participant>
          <Participant>
            <ParticipantRoleIs>
              <ParticipantRole  Value="Agent" />
            </ParticipantRoleIs>
            <FirstName>Agentname1</FirstName>
          </Participant>
        </ParticipantDetails>
      </Participants>
     </ns0:Schema>

Expected result

        <ns0:CreateClaim xmlns:ns0="http://Host_service_proj.Oubound_Test1">
          <Agent>Agentname1</Agent>
        </ns0:CreateClaim>

Scenario 2 Inputschema

    <ns0:Schema xmlns:ns0="urn:Test:esb:one:services:create:rq:1.0">
       <Participants>
        <ParticipantDetails>
          <Participant>
            <ParticipantRoleIs>
              <ParticipantRole  Value="" />
            </ParticipantRoleIs>
            <FirstName>FirstName_0</FirstName>
           </Participant>
       </ParticipantDetails>
      </Participants>
 </ns0:Schema>

Expected result

    <ns0:CreateClaim xmlns:ns0="http://Host_service_proj.Oubound_Test1">
      <Agent></Agent>
    </ns0:CreateClaim>

I am looking for the xslt for this mapping . I tried in scripting functod with inline xslt template

<xsl:template name="MyXsltConcatTemplate2">
<Agent>
 <xsl:value-of select="/*[local-name()='Schema' and namespace-uri()='http://Host_service_proj.Schema_test']/*[local-name()='Participatent' and namespace-uri()='']/*[local-name()='ParticipantDetails' and namespace-uri()='']/*[local-name()='Participant' and namespace-uri()='']/*[local-name()='Parturolecodes' and namespace-uri()='']/*[local-name()='PartyRole' and namespace-uri()=''][/@Value='Agent']/*[local-name()='FIRSTname' and namespace-uri()='']" />
</Agent>
</xsl:template>

But not getting expected result. Can anybody help here

2

There are 2 answers

0
al.truisme On BEST ANSWER

For XSLT 1.0, this may work you.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  
  <xsl:template match="/" >
    <xsl:element name="ns0:CreateClaim" namespace="'http://Host_service_proj.Oubound_Test1'">
      <xsl:element name="Agent" >
        <xsl:value-of 
        select="/*/*/*/Participant[ParticipantRoleIs/
                                   ParticipantRole/@Value = 'Agent']
                                   /FirstName[1]" />
      </xsl:element>
    </xsl:element>
  </xsl:template>
  
</xsl:stylesheet>
2
al.truisme On

You mention "input schemas" but, if I understand correctly, you are showing two different input instances.

The following in XSLT3.0 gives the outputs that you requested from the two given inputs. I see that BizTalk does support XSLT3.0 but that probably depends upon the version of BizTalk that you are using.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="3.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="#all"
  xmlns:in="urn:Test:esb:one:services:create:rq:1.0"
  xmlns:out="http://Host_service_proj.Oubound_Test1"
  expand-text="yes">
  
  <xsl:mode on-no-match="shallow-copy"/>
  
  <xsl:output indent="yes" />
  
  <xsl:variable name="out" as="xs:string" select="'http://Host_service_proj.Oubound_Test1'" />

  <xsl:template match="/" >
    <xsl:element name="ns0:CreateClaim" namespace="{$out}">
      <xsl:namespace name="ns0" select="$out" />
      <Agent>{/*/*/*/Participant[ParticipantRoleIs/ParticipantRole/@Value eq 'Agent']/FirstName[1]}</Agent>
    </xsl:element>
  </xsl:template>
  
</xsl:stylesheet>