英文:
BizTalk mapping inline XSLT
问题
<Agent><xsl:value-of select="$var:v2" /></Agent>
英文:
Input schema have field <Partycode Value="Agent" />
. Based on the this node I need to generate one destination node. Destination is single schema. If partycode is Agent I want destination node <Agent> with value of Fname.
If partycode is not agent I want destination node <Agent> without any value. <Participatent></Participatent>
unbounded in the schema. In destination is not unbounded
Scenario 1
Inputschema
<ns0:Schema xmlns:ns0="http://Host_service_proj.Inbound_test1">
<Participatent>
<ParticipantDetails>
<Participant>
<Partycode Value="" />
<FIRSTname>FIRSTname_0</FIRSTname>
</Participant>
<Participant>
<Partycode Value="Agent" />
<FIRSTname>Agentname1</FIRSTname>
</Participant>
</ParticipantDetails>
</Participatent>
</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="http://Host_service_proj.Inbound_test1">
<Participatent>
<ParticipantDetails>
<Participant>
<Partycode Value="" />
<FIRSTname>FIRSTname_0</FIRSTname>
</Participant>
</ParticipantDetails>
</Participatent>
</ns0:Schema>
Expected result
<ns0:CreateClaim xmlns:ns0="http://Host_service_proj.Oubound_Test1">
<Agent></Agent>
</ns0:CreateClaim>
I am trying to write inline xslt for this
<xsl:for-each select="Participatent/ParticipantDetails/Participant">
<xsl:variable name="var:v1" select="userCSharp:LogicalEq(string(Partycode/@Value) , &quot;Agent&quot;)" />
<xsl:if test="string($var:v1)='true'">
<xsl:variable name="var:v2" select="FIRSTname/text()" />
<Agent>
<xsl:value-of select="$var:v2" />
</Agent>
</xsl:if>
</xsl:for-each>
But I am not able to do blank <Agent>
in destination in the second scenario.
答案1
得分: 1
你需要使用choose而不是if,并且不要使用循环,只需使用XPath。
实际上,你不需要变量和条件判断,你可以使用XPath一行代码完成。
XPath中的`[Partycode/@Value='Agent']`部分选择了你想要的Participant节点。
如果有多个Partycode等于Agent的Participant,你可以指定只选择第一个。
英文:
You need to use choose rather than an if, and don't use a loop, just use XPath.
<xsl:variable name="var:v1" select="/*[local-name()='Schema' and namespace-uri()='http://Host_service_proj.Inbound_test1']/*[local-name()='Participatent' and namespace-uri()='']/*[local-name()='ParticipantDetails' and namespace-uri()='']/*[local-name()='Participant' and namespace-uri()=''][Partycode/@Value='Agent']/*[local-name()='FIRSTname' and namespace-uri()='']" />
<xsl:choose>
<xsl:when test="string($var:v1)!=''">
<Agent>
<xsl:value-of select="$var:v1" />
</Agent>
</xsl:when>
<xsl:otherwise>
<Agent>
</Agent>
</xsl:otherwise>
</xsl:choose>
In fact you don't need variables and a decision at all, you can do it with one line with XPath.
<Agent>
<xsl:value-of select="/*[local-name()='Schema' and namespace-uri()='http://Host_service_proj.Inbound_test1']/*[local-name()='Participatent' and namespace-uri()='']/*[local-name()='ParticipantDetails' and namespace-uri()='']/*[local-name()='Participant' and namespace-uri()=''][Partycode/@Value='Agent']/*[local-name()='FIRSTname' and namespace-uri()='']" />
</Agent>
Breaking the XPath down for readability, you can see part where it has [Partycode/@Value='Agent']
is the part that selects the Participant node you want.
/*[local-name()='Schema' and namespace-uri()='http://Host_service_proj.Inbound_test1']
/*[local-name()='Participatent' and namespace-uri()='']/*[local-name()='ParticipantDetails' and namespace-uri()='']
/*[local-name()='Participant' and namespace-uri()=''][Partycode/@Value='Agent']
/*[local-name()='FIRSTname' and namespace-uri()='']
And just in case you have more than one Participant with the Partycode = Agent, you can tell it to just select the first one.
/*[local-name()='Schema' and namespace-uri()='http://Host_service_proj.Inbound_test1']
/*[local-name()='Participatent' and namespace-uri()='']/*[local-name()='ParticipantDetails' and namespace-uri()='']
/*[local-name()='Participant' and namespace-uri()=''][Partycode/@Value='Agent'][1]
/*[local-name()='FIRSTname' and namespace-uri()='']
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论