2

我需要使用 xml 中的值生成 xls 文件。下面是我尝试执行的序列,但它只需要第一个结果。

<sequence xmlns="http://ws.apache.org/ns/synapse" name="ConcurTransformReconcilationExtractFlow">
   <property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="current-context-details" expression="concat(get-property('current-context-details'), ', ConcurTransformReconcilationExtractFlow')" />
   <property name="scenario" value="ConcurTransformReconcilationExtractFlow" />
   <log level="custom">
      <property name="DEBUGGING" value="ConcurTransformReconcilationExtractFlow" />
   </log>
   <log>
      <property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="datetime" expression="substring(get-property('current-date'),1,10)" />
      <property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="date" expression="substring-after(get-property('current-date'), 'T')" />
      <property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="time" expression="substring(substring-after(get-property('current-date'), 'T'), 1,8)" />
      <property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="current-datetime" expression="concat(substring(get-property('current-date'),1,10),substring(substring-after(get-property('current-date'), 'T'), 1,8))" />
   </log>
   <filter xmlns:dat="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" xpath="//dat:rows">
      <then>
         <xslt key="Concur_Group_Reconcilation_Extract_Transformation" />
         <log level="full" />
         <iterate expression="//sae" sequential="true">
            <target>
               <sequence>
                  <property name="company_code_sae_id" expression="concat('_',string(//@filename))" />
                  <log level="custom">
                     <property name="company_code_sae_id" expression="get-property('company_code_sae_id')" />
                  </log>
                  <property name="filename" expression="concat('Reconcilation_Extract_',substring(get-property('current-date'),1,10),'.xls')" />
                  <class name="com.semtech.integration.mediator.XMLToExcelMediator.XMLToExcelMediator" />
                  <property name="transport.vfs.ReplyFileName" expression="get-property('filename')" scope="transport" />
                  <property name="OUT_ONLY" value="true" />
                  <filter source="starts-with(get-property('company_code_sae_id'),'_')" regex="true">
                     <then>
                        <send>
                           <endpoint name="FileEpr">
                              <address uri="vfs:file:///exports/mounts/Concur/PaymentExtract" />
                           </endpoint>
                        </send>
                     </then>
                  </filter>
               </sequence>
            </target>
         </iterate>
      </then>
      <else>
         <enrich>
            <source clone="true" type="body" xpath="" property="" />
            <target action="replace" type="property" xpath="" property="body-message" />
         </enrich>
         <property name="error_message" expression="get-property('body-message')" />
         <property name="error_message" expression="concat('Invalid response received from data service:  ', get-property('error_message'))" />
         <log level="custom" category="ERROR">
            <property name="ConcurTransformReconcilationExtractFlow" expression="get-property('error_message')" />
         </log>
         <sequence key="GeneralErrorHandler" />
         <drop />
      </else>
   </filter>
   <description>Transforms the XML extract data service response to a xml file.</description>
</sequence>

xslt转换后的输入如下

<?xml version="1.0"?>
<rows>
<sae filename="30">
<row>
<sae_id>6</sae_id>
<sae_date>2012-08-13-07:00</sae_date>
<Co30>314.42</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>7</sae_id>
<sae_date>2012-08-20-07:00</sae_date>
<Co30>1456.62</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>10</sae_id>
<sae_date>2012-09-08-07:00</sae_date>
<Co30>1359.88</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>12</sae_id>
<sae_date>2012-09-18-07:00</sae_date>
<Co30>44.4</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>15</sae_id>
<sae_date>2012-09-24-07:00</sae_date>
<Co30>2142.47</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>19</sae_id>
<sae_date>2012-09-28-07:00</sae_date>
<Co30>3400.9</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>28</sae_id>
<sae_date>2012-10-03-07:00</sae_date>
<Co30>1243.89</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>33</sae_id>
<sae_date>2012-10-10-07:00</sae_date>
<Co30>101.88</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>36</sae_id>
<sae_date>2012-10-15-07:00</sae_date>
<Co30>2418.88</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>40</sae_id>
<sae_date>2012-10-22-07:00</sae_date>
<Co30>1499.57</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>41</sae_id>
<sae_date>2012-10-23-07:00</sae_date>
<Co30>925.88</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>43</sae_id>
<sae_date>2012-10-25-07:00</sae_date>
<Co30>37.0</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>44</sae_id>
<sae_date>2012-10-26-07:00</sae_date>
<Co30>1046.34</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>46</sae_id>
<sae_date>2012-10-30-07:00</sae_date>
<Co30>3760.52</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>51</sae_id>
<sae_date>2012-11-06-08:00</sae_date>
<Co30>1610.96</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>53</sae_id>
<sae_date>2012-11-08-08:00</sae_date>
<Co30>1962.57</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>53</sae_id>
<sae_date>2012-11-08-08:00</sae_date>
<Co30>868.0</Co30>
<payment_type>COPD</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>56</sae_id>
<sae_date>2012-11-13-08:00</sae_date>
<Co30>11384.52</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>56</sae_id>
<sae_date>2012-11-13-08:00</sae_date>
<Co30>2268.4</Co30>
<payment_type>COPD</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>59</sae_id>
<sae_date>2012-11-16-08:00</sae_date>
<Co30>750.15</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>61</sae_id>
<sae_date>2012-11-20-08:00</sae_date>
<Co30>1083.08</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>66</sae_id>
<sae_date>2012-11-27-08:00</sae_date>
<Co30>14624.52</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>66</sae_id>
<sae_date>2012-11-27-08:00</sae_date>
<Co30>5874.2</Co30>
<payment_type>COPD</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>69</sae_id>
<sae_date>2012-11-30-08:00</sae_date>
<Co30>19.96</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>71</sae_id>
<sae_date>2012-12-04-08:00</sae_date>
<Co30>595.13</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>75</sae_id>
<sae_date>2012-12-06-08:00</sae_date>
<Co30>685.47</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>76</sae_id>
<sae_date>2012-12-07-08:00</sae_date>
<Co30>1286.91</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay></row>
</sae>
</row>
</sae>
<sae filename="36">
<row>
<sae_id>53</sae_id>
<sae_date>2012-11-08-08:00</sae_date>
<Co36>631.8</Co36>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>56</sae_id>
<sae_date>2012-11-13-08:00</sae_date>
<Co36>1041.87</Co36>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>58</sae_id>
<sae_date>2012-11-15-08:00</sae_date>
<Co36>3197.3</Co36>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>66</sae_id>
<sae_date>2012-11-27-08:00</sae_date>
<Co36>4912.54</Co36>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>71</sae_id>
<sae_date>2012-12-04-08:00</sae_date>
<Co36>1008.42</Co36>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>76</sae_id>
<sae_date>2012-12-07-08:00</sae_date>
<Co36>46.62</Co36>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
</sae>
<sae filename="33">
<row>
<sae_id>56</sae_id>
<sae_date>2012-11-13-08:00</sae_date>
<Co33>200.43</Co33>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>56</sae_id>
<sae_date>2012-11-13-08:00</sae_date>
<Co33>950.2</Co33>
<payment_type>COPD</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>58</sae_id>
<sae_date>2012-11-15-08:00</sae_date>
<Co33>3231.53</Co33>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>62</sae_id>
<sae_date>2012-11-21-08:00</sae_date>
<Co33>156.66</Co33>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>62</sae_id>
<sae_date>2012-11-21-08:00</sae_date>
<Co33>2806.92</Co33>
<payment_type>COPD</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>66</sae_id>
<sae_date>2012-11-27-08:00</sae_date>
<Co33>291.48</Co33>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>69</sae_id>
<sae_date>2012-11-30-08:00</sae_date>
<Co33>47.78</Co33>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
</sae>
</rows>

并且输出需要是一个 xls 文件,其列如下

sae_id  sae_date  Co30 Co33 Co36 Payment_type concur_pay

在此之下,所有的值都应该被正确分配。上面的序列会这样做,但如果序列=“true”,则仅用于第一个值,如果序列=“false”,则仅用于最后一个值。请指导我获取所有值单个 xls 文件

4

1 回答 1

0

刚刚使用代理(见下面的代码)尝试了您的序列,并获取您的输入 XML(其中包含错误!)。那么它确实工作得很好。问题在这里:

当您循环遍历<sae>元素时(确实有效),您总是写入相同的文件名!属性transport.vfs.ReplyFileName总是一样的。因此,当您使用时,您将在输出文件sequential="true"中获得最后一个的内容。<sae>但是当你使用sequential="false"序列时并没有真正定义,你会得到任何元素。

在这里,我用 更改了输出文件名,company_cod_sae_id然后每个 sae 将有一个输出文件。

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="stackoverflow_xls" transports="vfs" startOnLoad="true" trace="disable">
  <parameter name="transport.PollInterval">5</parameter>
  <parameter name="transport.vfs.FileURI">C:/WSO2/StackOverflow/XLS</parameter>
  <parameter name="transport.vfs.FileNamePattern">.*.(XML|xml)$</parameter>
  <parameter name="transport.vfs.ContentType">application/xml</parameter>
  <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
  <parameter name="transport.vfs.MoveAfterProcess">C:/WSO2/StackOverflow/XLS/saved</parameter>
  <target faultSequence="errorSequence">
     <inSequence>
        <log level="full"/>
        <iterate expression="//sae" sequential="true">
           <target>
              <sequence>
                 <property name="company_code_sae_id" expression="concat('_',string(//@filename))"/>
                 <log level="custom">
                    <property name="company_code_sae_id" expression="get-property('company_code_sae_id')"/>
                 </log>
                 <!--<property name="filename" expression="concat('Reconcilation_Extract_',substring(get-property('current-date'),1,10),'.xls')"/>-->
                 <property name="filename" expression="concat('Reconcilation_Extract_',get-property('company_code_sae_id'),'.xls')"/>
                 <!--<class name="com.semtech.integration.mediator.XMLToExcelMediator.XMLToExcelMediator"/>-->
                 <property name="transport.vfs.ReplyFileName" expression="get-property('filename')" scope="transport"/>
                 <property name="OUT_ONLY" value="true"/>

                 <filter source="starts-with(get-property('company_code_sae_id'),'_')" regex="true">
                    <then>
                       <send>
                          <endpoint name="FileEpr">
                             <address uri="vfs:file://C:/WSO2/StackOverflow/XLS"/>
                          </endpoint>
                       </send>
                    </then>
                 </filter>
              </sequence>
           </target>
        </iterate>
     </inSequence>
  </target>

于 2012-12-21T10:47:51.043 回答