dictionaryxsltbiztalkbiztalk-2013r2

BizTalk inline XSLT in mapping


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


Solution

  • 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>