如何通过对某个职位分组来解决减法职位的问题

时间:2019-05-24 11:18:48

标签: xslt xslt-1.0

在我的xslt转换器中,我必须从一张发票中减去一些头寸,并按组显示。我不知道该怎么办。现在,我有了xslt,它在单独的位置给了我一个结果。

<Invoice>
    <P_1>2019.04.30</P_1>
    <P_2>FV_0660/E/2019</P_2>
    <P_3>Client</P_3>
    <P_4>Client Adress</P_4>
    <P_5>3570.9200</P_5>
    <P_6>821.3100</P_6>
    <P_7>4392.23</P_7>
</Invoice>
<InvoiceRecord typ="G">
    <P_8>FV_0660/E/2019</P_8>
    <P_9>Position1</P_9>
    <P_10>1707.10</P_10>
    <P_11>2099.73</P_11>
</InvoiceRecord>
<InvoiceRecord typ="G">
    <P_8>FV_0660/E/2019</P_8>
    <P_9>Position2 variable</P_9>
    <P_10>143.61</P_10>
    <P_11>176.64</P_11>
</InvoiceRecord>
<InvoiceRecord typ="G">
    <P_8>FV_0660/E/2019</P_8>
    <P_9>Position3</P_9>
    <P_10>0.00</P_10>
    <P_11>0.00</P_11>
</InvoiceRecord>
<InvoiceRecord typ="G">
    <P_8>FV_0660/E/2019</P_8>
    <P_9>Position4</P_9>
    <P_10>1086.47</P_10>
    <P_11>1336.36</P_11>
</InvoiceRecord>
<InvoiceRecord typ="G">
    <P_8>FV_0660/E/2019</P_8>
    <P_9>Position5 variable</P_9>
    <P_10>103.46</P_10>
    <P_11>127.26</P_11>
</InvoiceRecord>
<InvoiceRecord typ="G">
    <P_8>FV_0660/E/2019</P_8>
    <P_9>Position6</P_9>
    <P_10>384.38</P_10>
    <P_11>472.79</P_11>
</InvoiceRecord>
<InvoiceRecord typ="G">
    <P_8>FV_0660/E/2019</P_8>
    <P_9>Position7 variable</P_9>
    <P_10>32.34</P_10>
    <P_11>39.78</P_11>
</InvoiceRecord>
<InvoiceRecord typ="G">
    <P_8>FV_0660/E/2019</P_8>
    <P_9>Position8</P_9>
    <P_10>9.87</P_10>
    <P_11>12.14</P_11>
</InvoiceRecord>
<InvoiceRecord typ="G">
    <P_8>FV_0660/E/2019</P_8>
    <P_9>Position9</P_9>
    <P_10>103.69</P_10>
    <P_11>127.54</P_11>
</InvoiceRecord>

现在我得到结果

 Position1 1707.10
 Position2 variable 143.61 etc.

我需要的结果是这样的

Positions 3291.51
PositionsV 279.41

我需要不带单词变量的仓位总和和带变量的第二个总和。也许有人可以帮助我解决这个问题。

1 个答案:

答案 0 :(得分:1)

给出格式正确的输入,例如:

XML

<input>
    <Invoice>
        <P_1>2019.04.30</P_1>
        <P_2>FV_0660/E/2019</P_2>
        <P_3>Client</P_3>
        <P_4>Client Adress</P_4>
        <P_5>3570.9200</P_5>
        <P_6>821.3100</P_6>
        <P_7>4392.23</P_7>
    </Invoice>
    <InvoiceRecord typ="G">
        <P_8>FV_0660/E/2019</P_8>
        <P_9>Position1</P_9>
        <P_10>1707.10</P_10>
        <P_11>2099.73</P_11>
    </InvoiceRecord>
    <InvoiceRecord typ="G">
        <P_8>FV_0660/E/2019</P_8>
        <P_9>Position2 variable</P_9>
        <P_10>143.61</P_10>
        <P_11>176.64</P_11>
    </InvoiceRecord>
    <InvoiceRecord typ="G">
        <P_8>FV_0660/E/2019</P_8>
        <P_9>Position3</P_9>
        <P_10>0.00</P_10>
        <P_11>0.00</P_11>
    </InvoiceRecord>
    <InvoiceRecord typ="G">
        <P_8>FV_0660/E/2019</P_8>
        <P_9>Position4</P_9>
        <P_10>1086.47</P_10>
        <P_11>1336.36</P_11>
    </InvoiceRecord>
    <InvoiceRecord typ="G">
        <P_8>FV_0660/E/2019</P_8>
        <P_9>Position5 variable</P_9>
        <P_10>103.46</P_10>
        <P_11>127.26</P_11>
    </InvoiceRecord>
    <InvoiceRecord typ="G">
        <P_8>FV_0660/E/2019</P_8>
        <P_9>Position6</P_9>
        <P_10>384.38</P_10>
        <P_11>472.79</P_11>
    </InvoiceRecord>
    <InvoiceRecord typ="G">
        <P_8>FV_0660/E/2019</P_8>
        <P_9>Position7 variable</P_9>
        <P_10>32.34</P_10>
        <P_11>39.78</P_11>
    </InvoiceRecord>
    <InvoiceRecord typ="G">
        <P_8>FV_0660/E/2019</P_8>
        <P_9>Position8</P_9>
        <P_10>9.87</P_10>
        <P_11>12.14</P_11>
    </InvoiceRecord>
    <InvoiceRecord typ="G">
        <P_8>FV_0660/E/2019</P_8>
        <P_9>Position9</P_9>
        <P_10>103.69</P_10>
        <P_11>127.54</P_11>
    </InvoiceRecord>
</input>

以下样式表:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/input">
    <output>
        <positions>
            <xsl:value-of select="sum(InvoiceRecord[not(contains(P_9, 'variable'))]/P_10)"/>
        </positions>
        <positionsV>
            <xsl:value-of select="sum(InvoiceRecord[contains(P_9, 'variable')]/P_10)"/>
        </positionsV>
    </output>
</xsl:template>

</xsl:stylesheet>

将返回:

结果

<?xml version="1.0" encoding="UTF-8"?>
<output>
  <positions>3291.51</positions>
  <positionsV>279.41</positionsV>
</output>