如何跳出循环并访问以前的元素

时间:2013-11-20 08:26:25

标签: xpath xslt-1.0

有一个XML结构:

<INFO>
<para Type="07">07    L„hetysluettelo</para>
                            <para Type="+0">+0                     074064</para>
                            <para Type="07">07    Tilausnumero            Ostajan viite</para>
                            <para Type="+0">+0                  044275                   5549177</para>
                            <para Type=" 0"> 0    836679586 (LONG               2478      3.63                      8995.14</para>
                            <para Type="07">07    L„hetysluettelo2</para>
                            <para Type="+0">+0                     074517</para>
                            <para Type="07">07    Tilausnumero            Ostajan viite</para>
                            <para Type="+0">+0                  044276                   5534435</para>
                            <para Type=" 0"> 0    836679586 (LONG               2478      3.63                      8995.14</para>
                            <para Type=" 0"> 0    L1 KUORMAL. 800                 14      0.00                         0.00</para>
</INFO>

我想在para类型SPACE0上使用loop。通过这样做,我还想获取其先前的数据元素,例如:+0和07段。

我正在寻找这个输出:

<ROWS>
<ROW>
<NUMBER>074064</NUMBER>
<ORDER_NUMBER>044275</ORDER_NUMBER>
<REF>5549177</REF>
<NAME>836679586 (LONG</NAME>
<COUNT>2478</COUNT>
<PRICE>3.63</PRICE>
<TOTAL>8995.14</TOTAL>
</ROW>
<ROW>
<NUMBER>074517</NUMBER>
<ORDER_NUMBER>044276</ORDER_NUMBER>
<REF>5534435</REF>
<NAME>836679586 (LONG</NAME>
<COUNT>2478</COUNT>
<PRICE>3.63</PRICE>
<TOTAL>8995.14</TOTAL>
</ROW>
<ROW>
<NUMBER>074517</NUMBER>
<ORDER_NUMBER>044276</ORDER_NUMBER>
<REF>5534435</REF>
<NAME>L1 KUORMAL. 800</NAME>
<COUNT>14</COUNT>
<PRICE>0.00</PRICE>
<TOTAL>0.00</TOTAL>
</ROW>
</ROWS>

在某些情况下,元素NUMBER,ORDER_NUMBER和REF值将保持不变,因为它们属于同一段。

是否可以这样做?

我试过这个:

<xsl:for-each select="INFO/para[@Type=' 0']">
                    <ROW>

                            <NUMBER>
                                <xsl:value-of select="normalize-space(substring(../following-sibling::para[1],6,24))"/>
                            </NUMBER>

                                                                        <ORDER_NUMBER>
                                    <xsl:value-of select="normalize-space(substring(../following-sibling::para[3],7,24))"/>
                                </ORDER_NUMBER>
                                <REF>
                                    <xsl:value-of select="normalize-space(substring(../following-sibling::para[3],31,50))"/>
                                </REF>
    <NAME>
                                <xsl:value-of select="normalize-space(substring(.,7,24))"/>
                            </NAME>
    <COUNT>
                                <xsl:value-of select="normalize-space(substring(.,33,8))"/>
                            </COUNT>



                        <PRICE>
    <xsl:value-of select="normalize-space(substring(.,41,11))"/>
                                                </PRICE>
                                            <TOTAL>
    <xsl:value-of select="normalize-space(substring(.,69,11))"/>
                                                </TOTAL>
                    </ROW>
                </xsl:for-each>

感谢。

0 个答案:

没有答案