如何使用BW mapper将一个XML中的值替换为另一个xml?

时间:2013-05-15 21:19:55

标签: xslt xslt-1.0 tibco

我有以下xml:

usa11.xml:

<?xml version="1.0" encoding="UTF-8"?>
<country  xmlns="http://www.tibco.com/xmlns/ApplicationManagement" >
  <state name="CA">
    <city>
      <street>El Comino Ave.</street>
    <library>library 11111.</library>
    </city>
    <city>
    <street>DeAnza Ave.</street>
  <library>library 22222.</library>
    </city>
    <city>
         <street>shoreline Ave.</street>
    <library>library 33333.</library>
    </city>
  </state>
</country>

和另一个xml: usa22.xml:

<?xml version="1.0" encoding="UTF-8"?>
 <country xmlns="http://www.tibco.com/xmlns/ApplicationManagement" >
   <state name="CA">
  <city>
           <street>El Comino Ave.</street>
      <library>library AAAAA.</library>
       </city>
  <city>
            <street>DeAnza Ave.</street>
       <library>library BBBBB.</library>
       </city>
  </state>
</country>

然后我希望使用Tibco BW mapper来使用usa22.xml的元素vaules来替换usa11.xml的那些只有它们的街道名称相同:然后得到输出usa33.xml如下out.xml:

<?xml version="1.0" encoding="UTF-8"?>
<country xmlns="http://www.tibco.com/xmlns/ApplicationManagement">
  <state name="CA">
      <city>
           <street>El Comino Ave.</street>
           <library>library AAAAA.</library>
      </city>
      <city>
           <street>DeAnza Ave.</street>
           <library>library BBBBB.</library>
      </city>
      <city>
             <street>shoreline Ave.</street>
        <library>library 33333.</library>
      </city>
  </state>
</country>

请注意如何使用Tibco BW mapper来替换??

架构如下:

usa.xsd:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.tibco.com/xmlns/ApplicationManagement" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="country">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="state">
        <xs:complexType>
        <xs:sequence>
          <xs:element name="city" maxOccurs="unbounded" minOccurs="0">
            <xs:complexType>
              <xs:sequence>
                <xs:element type="xs:string" name="street"/>
                <xs:element type="xs:string" name="library"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
        <xs:attribute type="xs:string" name="name"/>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
  </xs:complexType>
  </xs:element>
</xs:schema>

非常感谢!!!

1 个答案:

答案 0 :(得分:2)

执行您要求的简单方法是在BW流程中将一个XML / Parse XML活动放在一个Group中,并使其遍历您的usa11.xml。在每个循环中,您可以通过xPath做出决定,并选择是否替换当前内容  元素与否。

Link to Designer screenshot

希望有所帮助!