XSLT转换:源XLS中单个元素的多个元素

时间:2016-03-07 13:22:29

标签: xslt

请忍受我冗长的请求,我对XSLT非常陌生,所以面对这些问题。 下面是输入源XML,我需要转换它以按照输出XSD写入数据。请在这方面帮助我。

=====

开始输入XML

<?xml version="1.0" encoding="UTF-8"?><Receive_Read852File_Read_IV>
   <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="body">
      <Transaction-852 xmlns="http://www.edifecs.com/xdata/200" XDataVersion="2.0" Standard="X12" Version="V4010" CreatedDate="2016-03-03T13:49:27" CreatedBy="XEngine_3016" GUID="{BF24BE6C-E146-11E5-8E7D-005056A223A6}">
    <Internal-Properties>
        <Data-Structure Name="Interchange">
            <Lookup Name="InterchangeControlVersion">00400</Lookup>
            <Property Name="ElementDelimiter">0x2a</Property>
            <Data-Structure Name="Group">
                <Lookup Name="GroupSenderID">000099999</Lookup>
                <Lookup Name="GroupVersionNumber">004010</Lookup>
                <Property Name="GroupAgencyCode">X</Property>
                <Property Name="GroupControlNumber">43350</Property>
                <Data-Structure Name="Transaction">
                    <Lookup Name="TransactionID">852</Lookup>
                    <Property Name="TransactionTrailerControlNumber">0001</Property>
                </Data-Structure>
            </Data-Structure>
        </Data-Structure>
    </Internal-Properties>
    <Segment-ST>
        <Element-143>852</Element-143>
        <Element-329>0001</Element-329>
    </Segment-ST>
    <Segment-XQ>
        <Element-305>H</Element-305>
        <Element-373>20140105</Element-373>
        <Element-373_1>20140111</Element-373_1>
    </Segment-XQ>
    <Loop-LIN>
        <Segment-LIN>
            <Element-350>001</Element-350>
            <Element-235>UP</Element-235>
            <Element-234>722868102237</Element-234>
            <Element-235_1>VP</Element-235_1>
            <Element-234_1>F2N036-06</Element-234_1>
        </Segment-LIN>
        <Loop-ZA>
            <Segment-ZA>
                <Element-859>QS</Element-859>
            </Segment-ZA>
            <Segment-SDQ>
                <Element-355>EA</Element-355>
                <Element-66>92</Element-66>
                <Element-67>008</Element-67>
                <Element-380>1</Element-380>
                <Element-67_1>018</Element-67_1>
                <Element-380_1>1</Element-380_1>
                <Element-67_2>027</Element-67_2>
                <Element-380_2>1</Element-380_2>
            </Segment-SDQ>
        </Loop-ZA>
    </Loop-LIN>
    <Loop-LIN>
        <Segment-LIN>
            <Element-350>002</Element-350>
            <Element-235>UP</Element-235>
            <Element-234>722868127469</Element-234>
            <Element-235_1>VP</Element-235_1>
            <Element-234_1>F2N025-10-GLD</Element-234_1>
        </Segment-LIN>
        <Loop-ZA>
            <Segment-ZA>
                <Element-859>QS</Element-859>
            </Segment-ZA>
            <Segment-SDQ>
                <Element-355>EA</Element-355>
                <Element-66>92</Element-66>
                <Element-67>007</Element-67>
                <Element-380>1</Element-380>
                <Element-67_1>010</Element-67_1>
                <Element-380_1>1</Element-380_1>
                <Element-67_2>017</Element-67_2>
                <Element-380_2>1</Element-380_2>
                <Element-67_3>020</Element-67_3>
                <Element-380_3>1</Element-380_3>
                <Element-67_4>021</Element-67_4>
                <Element-380_4>1</Element-380_4>
                <Element-67_5>022</Element-67_5>
                <Element-380_5>1</Element-380_5>
                <Element-67_6>025</Element-67_6>
                <Element-380_6>1</Element-380_6>
                <Element-67_7>028</Element-67_7>
                <Element-380_7>2</Element-380_7>
                <Element-67_8>048</Element-67_8>
                <Element-380_8>1</Element-380_8>
            </Segment-SDQ>
        </Loop-ZA>
    </Loop-LIN>
    <Segment-SE>
        <Element-96>1545</Element-96>
        <Element-329>0001</Element-329>
    </Segment-SE>
</Transaction-852>
   </part>

结束输入XML

=================

开始输出XSD

<?xml version="1.0" encoding="UTF-8"?>
<!-- Automatically generated by EDIFECS SpecBuilder (http://www.edifecs.com) -->
<xsd:schema xmlns="http://www.edifecs.com/xdata/200" targetNamespace="http://www.edifecs.com/xdata/200" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0" elementFormDefault="qualified">
    <xsd:element name="Transaction-852">
        <xsd:complexType name="Record-Record1">
        <xsd:sequence>
            <xsd:element name="Field-TP_CODE" type="xsd:string"/>
            <xsd:element name="Field-DATE" type="xsd:string"/>
            <xsd:element name="Field-Customer_Part_Number" type="xsd:string"/>
            <xsd:element name="Field-UPC" type="xsd:string"/>
            <xsd:element name="Field-BELKIN_PART" type="xsd:string"/>
            <xsd:element name="Field-CTP_UNIT_PRICE" type="xsd:string"/>
            <xsd:element name="Field-ACTIVITY" type="xsd:string"/>
            <xsd:element name="Field-StoreNumber" type="xsd:string"/>
            <xsd:element name="Field-QTY" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
    </Transaction-852>
</xsd:schema>

=================

END输出XSD

现在映射条件是:

  1. 来源&GT; &#34;事务-852&GT;段XQ&GT;元件-373&#34;应该映射到&#34; Transaction-852&gt;记录 - 记录1&gt;场-DATE&#34;目标方
  2. 来源&GT; &#34;事务-852&GT; Loop-LIN&gt; Segment-LIN&gt;元件-350&#34;应该映射到&#34; Transaction-852&gt;记录 - 记录1&gt;场UPC&#34;目标方
  3. 来源&GT; &#34;事务-852&GT; Loop-LIN&gt; Segment-LIN&gt;元件-234&#34;应该映射到&#34; Transaction-852&gt;记录 - 记录1&gt;场BELKIN_PART&#34;目标方
  4. 来源&GT; &#34;事务-852&GT; Loop-LIN&gt;环-ZA&GT;段-ZA>元件-859&#34;应该映射到&#34; Transaction-852&gt;记录 - 记录1&gt;场-ACTIVITY&#34;目标方
  5. 来源&GT; &#34;事务-852&GT; Loop-LIN&gt;环-ZA&GT;段-SDQ&gt;元件-67&#34;应该映射到&#34; Transaction-852&gt;记录 - 记录1&gt;场StoreNumber&#34;目标方
  6. 来源&GT; &#34;事务-852&GT; Loop-LIN&gt;环-ZA&GT;段-SDQ&gt;元件-380&#34;应该映射到&#34; Transaction-852&gt;记录 - 记录1&gt;场QTY&#34;目标方
  7. 现在,映射条件5和6将重复所有元素开始&#34;元素-67&#34;元素-67_9和元素380到元素-380_9取决于元素的可用性。

    我尝试使用For-each条件进行映射1到3,但在尝试映射4和5时遇到问题。 请帮我解决这个问题。

    必需的输出XML格式:

    <Transaction-852> 
    <Record-Record1> 
    <Field-TP_CODE>THD</Field-TP_CODE>
    <Field-UPC>001</Field-UPC>
    <Field-DATE>20140105</Field-DATE>
    <Field-BELKIN_PART>722868102237</Field-BELKIN_PART>
    <Field-ACTIVITY>QS</Field-ACTIVITY>
    <Field-StoreNumber>008</Field-StoreNumber>
    <Field-QTY>1</Field-QTY>
    </Record-Record1>
    <Record-Record1> 
    <Field-TP_CODE>THD</Field-TP_CODE>
    <Field-UPC>001</Field-UPC>
    <Field-DATE>20140105</Field-DATE>
    <Field-BELKIN_PART>722868102237</Field-BELKIN_PART>
    <Field-ACTIVITY>QS</Field-ACTIVITY>
    <Field-StoreNumber>018</Field-StoreNumber>
    <Field-QTY>1</Field-QTY>
    </Record-Record1>
    <Record-Record1> 
    <Field-TP_CODE>THD</Field-TP_CODE>
    <Field-UPC>001</Field-UPC>
    <Field-DATE>20140105</Field-DATE>
    <Field-BELKIN_PART>722868102237</Field-BELKIN_PART>
    <Field-ACTIVITY>QS</Field-ACTIVITY>
    <Field-StoreNumber>027</Field-StoreNumber>
    <Field-QTY>1</Field-QTY>
    </Record-Record1>
    <Record-Record1> 
    <Field-TP_CODE>THD</Field-TP_CODE>
    <Field-UPC>002</Field-UPC>
    <Field-DATE>20140105</Field-DATE>
    <Field-BELKIN_PART>722868127469</Field-BELKIN_PART>
    <Field-ACTIVITY>QS</Field-ACTIVITY>
    <Field-StoreNumber>007</Field-StoreNumber>
    <Field-QTY>1</Field-QTY>
    </Record-Record1>
    <Record-Record1> 
    <Field-TP_CODE>THD</Field-TP_CODE>
    <Field-UPC>002</Field-UPC>
    <Field-DATE>20140105</Field-DATE>
    <Field-BELKIN_PART>722868127469</Field-BELKIN_PART>
    <Field-ACTIVITY>QS</Field-ACTIVITY>
    <Field-StoreNumber>010</Field-StoreNumber>
    <Field-QTY>1</Field-QTY>
    </Record-Record1>
    .
    .
    .
    </Transaction-852>
    

    我尝试使用For-each条件进行映射1到3,但是在尝试映射4和5时面临问题,只有第一个记录(Element-67)被映射,其余的则抛出错误。 请帮我解决这个问题。

0 个答案:

没有答案