BizTalk映射中的内联XSLT

huangapple go评论48阅读模式
英文:

BizTalk inline XSLT in mapping

问题

Input schema有一个字段<Partycode Value="Agent" />。基于这个节点,我需要生成一个目标节点。目标节点是单一的模式。如果partycode是Agent,我想要一个值为Fname的目标节点。

如果partycode不是代理商,我希望目标节点没有任何值。
<Participatent></Participatent>在模式<ParticipantRole >中也没有限制,但代理商的值只有一次<participant>部分。

在目标中不是无限的。

场景1输入模式

    &lt;ns0:Schema xmlns:ns0=&quot;urn:Test:esb:one:services:create:rq:1.0&quot;&gt;
       &lt;Participants&gt;
        &lt;ParticipantDetails&gt;
          &lt;Participant&gt;
            &lt;ParticipantRoleIs&gt;
              &lt;ParticipantRole  Value=&quot;&quot; /&gt;
            &lt;/ParticipantRoleIs&gt;
            &lt;FirstName&gt;FirstName_0&lt;/FirstName&gt;
          &lt;/Participant&gt;
          &lt;Participant&gt;
            &lt;ParticipantRoleIs&gt;
              &lt;ParticipantRole  Value=&quot;Agent&quot; /&gt;
            &lt;/ParticipantRoleIs&gt;
            &lt;FirstName&gt;Agentname1&lt;/FirstName&gt;
          &lt;/Participant&gt;
        &lt;/ParticipantDetails&gt;
      &lt;/Participants&gt;
     &lt;/ns0:Schema&gt;

期望的结果

        &lt;ns0:CreateClaim xmlns:ns0=&quot;http://Host_service_proj.Oubound_Test1&quot;&gt;
          &lt;Agent&gt;Agentname1&lt;/Agent&gt;
        &lt;/ns0:CreateClaim&gt;

场景2输入模式

    &lt;ns0:Schema xmlns:ns0=&quot;urn:Test:esb:one:services:create:rq:1.0&quot;&gt;
       &lt;Participants&gt;
        &lt;ParticipantDetails&gt;
          &lt;Participant&gt;
            &lt;ParticipantRoleIs&gt;
              &lt;ParticipantRole  Value=&quot;&quot; /&gt;
            &lt;/ParticipantRoleIs&gt;
            &lt;FirstName&gt;FirstName_0&lt;/FirstName&gt;
           &lt;/Participant&gt;
       &lt;/ParticipantDetails&gt;
      &lt;/Participants&gt;
 &lt;/ns0:Schema&gt;

期望的结果

    &lt;ns0:CreateClaim xmlns:ns0=&quot;http://Host_service_proj.Oubound_Test1&quot;&gt;
      &lt;Agent&gt;&lt;/Agent&gt;
    &lt;/ns0:CreateClaim&gt;

我正在寻找此映射的XSLT。我尝试在内联XSLT模板中使用脚本函数

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

但没有得到预期的结果。有人可以帮助吗?

英文:

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 with value of Fname.

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

Scenario 1 Inputschema

    &lt;ns0:Schema xmlns:ns0=&quot;urn:Test:esb:one:services:create:rq:1.0&quot;&gt;
       &lt;Participants&gt;
        &lt;ParticipantDetails&gt;
          &lt;Participant&gt;
            &lt;ParticipantRoleIs&gt;
              &lt;ParticipantRole  Value=&quot;&quot; /&gt;
            &lt;/ParticipantRoleIs&gt;
            &lt;FirstName&gt;FirstName_0&lt;/FirstName&gt;
          &lt;/Participant&gt;
          &lt;Participant&gt;
            &lt;ParticipantRoleIs&gt;
              &lt;ParticipantRole  Value=&quot;Agent&quot; /&gt;
            &lt;/ParticipantRoleIs&gt;
            &lt;FirstName&gt;Agentname1&lt;/FirstName&gt;
          &lt;/Participant&gt;
        &lt;/ParticipantDetails&gt;
      &lt;/Participants&gt;
     &lt;/ns0:Schema&gt;

Expected result

        &lt;ns0:CreateClaim xmlns:ns0=&quot;http://Host_service_proj.Oubound_Test1&quot;&gt;
          &lt;Agent&gt;Agentname1&lt;/Agent&gt;
        &lt;/ns0:CreateClaim&gt;

Scenario 2 Inputschema

    &lt;ns0:Schema xmlns:ns0=&quot;urn:Test:esb:one:services:create:rq:1.0&quot;&gt;
       &lt;Participants&gt;
        &lt;ParticipantDetails&gt;
          &lt;Participant&gt;
            &lt;ParticipantRoleIs&gt;
              &lt;ParticipantRole  Value=&quot;&quot; /&gt;
            &lt;/ParticipantRoleIs&gt;
            &lt;FirstName&gt;FirstName_0&lt;/FirstName&gt;
           &lt;/Participant&gt;
       &lt;/ParticipantDetails&gt;
      &lt;/Participants&gt;
 &lt;/ns0:Schema&gt;

Expected result

    &lt;ns0:CreateClaim xmlns:ns0=&quot;http://Host_service_proj.Oubound_Test1&quot;&gt;
      &lt;Agent&gt;&lt;/Agent&gt;
    &lt;/ns0:CreateClaim&gt;

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

&lt;xsl:template name=&quot;MyXsltConcatTemplate2&quot;&gt;
&lt;Agent&gt;
 &lt;xsl:value-of select=&quot;/*[local-name()=&#39;Schema&#39; and namespace-uri()=&#39;http://Host_service_proj.Schema_test&#39;]/*[local-name()=&#39;Participatent&#39; and namespace-uri()=&#39;&#39;]/*[local-name()=&#39;ParticipantDetails&#39; and namespace-uri()=&#39;&#39;]/*[local-name()=&#39;Participant&#39; and namespace-uri()=&#39;&#39;]/*[local-name()=&#39;Parturolecodes&#39; and namespace-uri()=&#39;&#39;]/*[local-name()=&#39;PartyRole&#39; and namespace-uri()=&#39;&#39;][/@Value=&#39;Agent&#39;]/*[local-name()=&#39;FIRSTname&#39; and namespace-uri()=&#39;&#39;]&quot; /&gt;
&lt;/Agent&gt;
&lt;/xsl:template&gt;

But not getting expected result. Can anybody help here

答案1

得分: 1

对于XSLT 1.0,这可能适用于您。

<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>
英文:

For XSLT 1.0, this may work you.

&lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
  version=&quot;1.0&quot;&gt;
  
  &lt;xsl:template match=&quot;/&quot; &gt;
    &lt;xsl:element name=&quot;ns0:CreateClaim&quot; namespace=&quot;&#39;http://Host_service_proj.Oubound_Test1&#39;&quot;&gt;
      &lt;xsl:element name=&quot;Agent&quot; &gt;
        &lt;xsl:value-of 
        select=&quot;/*/*/*/Participant[ParticipantRoleIs/
                                   ParticipantRole/@Value = &#39;Agent&#39;]
                                   /FirstName[1]&quot; /&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  
&lt;/xsl:stylesheet&gt;

答案2

得分: 0

以下是您提供的文本的中文翻译:

您提到了“输入模式”,但如果我理解正确,您展示了两个不同的输入实例。

以下是XSLT3.0中的代码,它提供了您从两个给定的输入中请求的输出。我看到BizTalk确实支持XSLT3.0,但这可能取决于您使用的BizTalk版本。

<?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>
英文:

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.

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

  &lt;xsl:template match=&quot;/&quot; &gt;
    &lt;xsl:element name=&quot;ns0:CreateClaim&quot; namespace=&quot;{$out}&quot;&gt;
      &lt;xsl:namespace name=&quot;ns0&quot; select=&quot;$out&quot; /&gt;
      &lt;Agent&gt;{/*/*/*/Participant[ParticipantRoleIs/ParticipantRole/@Value eq &#39;Agent&#39;]/FirstName[1]}&lt;/Agent&gt;
    &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  
&lt;/xsl:stylesheet&gt;

huangapple
  • 本文由 发表于 2023年6月8日 19:10:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76431231.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定