平面文件数据映射到兄弟节点

时间:2015-11-10 15:49:50

标签: xslt biztalk biztalk-mapper

我有一个平面文件,每个记录都是客户,并且该记录中有一个shipto和billto地址。输出模式具有带有地址子节点的客户记录。我不知道如何将传入记录中的2个地址映射到客户记录的兄弟节点。

我有一个输入文件,定义如下:

<customer>
    <customernum/>
    <shipaddrcity/>
    <shipaddrstate/>
    <shipaddrzip/>
    <billaddrcity/>
    <billaddrstate/>
    <billaddrzip/>
</customer>

输出最终需要看起来像:

<customer>
    <customernum/>
    <addr>
        <type/>
        <city/>
        <state/>
        <zip/>
    </addr> 
    <addr>
        <type/>
        <city/>
        <state/>
        <zip/>
    </addr>
</customer>

我对biztalk很新,并且无法找到任何使用Biztalk Mapper完成此操作的正确示例。我也愿意听x6lt如何做到这一点。

1 个答案:

答案 0 :(得分:3)

你可能想要一些特定于BizTalk的东西,而且我对BizTalk一无所知,但这可能对你有所帮助。

给出输入文件......

<customers>
<customer>
    <customernum>1</customernum>
    <shipaddrcity>Cairns</shipaddrcity>
    <shipaddrstate>QLD</shipaddrstate>
    <shipaddrzip>b</shipaddrzip>
    <billaddrcity>Sydney</billaddrcity>
    <billaddrstate>NSW</billaddrstate>
    <billaddrzip>c</billaddrzip>
</customer>
<customer>
    <customernum>2</customernum>
    <shipaddrcity>d</shipaddrcity>
    <shipaddrstate>WA</shipaddrstate>
    <shipaddrzip>e</shipaddrzip>
    <billaddrcity>Melbourne</billaddrcity>
    <billaddrstate>Vic</billaddrstate>
    <billaddrzip>f</billaddrzip>
</customer>
</customers>

...这个XSLT 1.0样式表......

<xsl:transform
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

<xsl:output omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="customer">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()[not(
      self::shipaddrstate|
      self::shipaddrzip  |
      self::billaddrstate|
      self::billaddrzip   )]"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="shipaddrcity">
  <addr>
    <type>ship</type>
    <city><xsl:value-of select="." /></city>
    <xsl:apply-templates select="../(shipaddrstate|shipaddrzip)" />
  </addr> 
</xsl:template>

<xsl:template match="billaddrcity">
  <addr>
    <type>bill</type>
    <city><xsl:value-of select="." /></city>
    <xsl:apply-templates select="../(billaddrstate|billaddrzip)" />
  </addr> 
</xsl:template>

<xsl:template match="shipaddrstate|billaddrstate">
  <state><xsl:value-of select="." /></state>
</xsl:template>

<xsl:template match="shipaddrzip|billaddrzip">
  <zip><xsl:value-of select="." /></zip>
</xsl:template>

</xsl:transform>

...当应用于输入文档时,将产生...

<customers>
   <customer>
      <customernum>1</customernum>
      <addr>
         <type>ship</type>
         <city>Cairns</city>
         <state>QLD</state>
         <zip>b</zip>
      </addr>
      <addr>
         <type>bill</type>
         <city>Sydney</city>
         <state>NSW</state>
         <zip>c</zip>
      </addr>
   </customer>
   <customer>
      <customernum>2</customernum>
      <addr>
         <type>ship</type>
         <city>d</city>
         <state>WA</state>
         <zip>e</zip>
      </addr>
      <addr>
         <type>bill</type>
         <city>Melbourne</city>
         <state>Vic</state>
         <zip>f</zip>
      </addr>
   </customer>
</customers>