如何在我的代码中使用正确的 Max 函数?

丁克

早上好,

我的代码中有相同的节点,它们都有其他百分比。我只想要百分比最高的节点。我似乎无法让我的代码正确。有没有办法在这个上使用 max 函数?

<xsl:template match="/">
  <xsl:for-each select="/x:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory">
     <xsl:choose>
    <xsl:when test="count(cbc:Percent) = 1">
        <xsl:value-of select="format-number(cbc:Percent,'00')"/>
    </xsl:when>
    <xsl:otherwise>
          <xsl:value-of select="21"/>
    </xsl:otherwise>
</xsl:choose>
  </xsl:for-each>
</xsl:template>

我试过上面的代码。现在我得到结果 0021212121。所以代码选择了 cbc:Percent 中的所有字段。

<InvoiceLine>
<ID>1</ID>
<InvoicedQuantity/>
<LineExtensionAmount currencyID="EUR">0.00</LineExtensionAmount>
<OrderLineReference>
<LineID>1</LineID>
<OrderReference>
<ID>351450.27</ID>
</OrderReference>
</OrderLineReference>
<TaxTotal>
<TaxAmount currencyID="EUR">0.00</TaxAmount>
<TaxSubtotal>
<TaxableAmount currencyID="EUR">0.00</TaxableAmount>
<TaxAmount currencyID="EUR">0.00</TaxAmount>
<TaxCategory>
<ID>NA</ID>
<Percent>0</Percent>
<TaxScheme/>
</TaxCategory>
</TaxSubtotal>
</TaxTotal>
<Item>
<Description>685000 / 08.0005 /filiaal: 2666 / ref1: 
 `351450.27</Description>`
<SellersItemIdentification>
<ID/>
</SellersItemIdentification>
</Item>
<Price>
<PriceAmount currencyID="EUR">0.00</PriceAmount>
<BaseQuantity>1</BaseQuantity>
</Price>
</InvoiceLine>
<InvoiceLine>
<ID>2</ID>
<InvoicedQuantity>2</InvoicedQuantity>
<LineExtensionAmount currencyID="EUR">19.76</LineExtensionAmount>
<OrderLineReference>
<LineID>2</LineID>
<OrderReference>
<ID>351450.27</ID>
</OrderReference>
</OrderLineReference>
<TaxTotal>
<TaxAmount currencyID="EUR">4.15</TaxAmount>
<TaxSubtotal>
<TaxableAmount currencyID="EUR">19.76</TaxableAmount>
<TaxAmount currencyID="EUR">4.15</TaxAmount>
<TaxCategory>
<ID>Excluding</ID>
<Percent>21</Percent>
<TaxScheme/>
</TaxCategory>
</TaxSubtotal>
</TaxTotal>
<Item>
<Description>BLABLA</Description>
<SellersItemIdentification>
<ID>96184323</ID>
</SellersItemIdentification>
</Item>
<Price>
<PriceAmount currencyID="EUR">9.88</PriceAmount>
<BaseQuantity>1</BaseQuantity>
</Price>
</InvoiceLine>
<InvoiceLine>
<ID>3</ID>
<InvoicedQuantity>10</InvoicedQuantity>
<LineExtensionAmount currencyID="EUR">12.00</LineExtensionAmount>
<OrderLineReference>
<LineID>3</LineID>
<OrderReference>
<ID>351450.27</ID>
</OrderReference>
</OrderLineReference>
<TaxTotal>
<TaxAmount currencyID="EUR">2.52</TaxAmount>
<TaxSubtotal>
<TaxableAmount currencyID="EUR">12.00</TaxableAmount>
<TaxAmount currencyID="EUR">2.52</TaxAmount>
<TaxCategory>
<ID>Excluding</ID>
<Percent>21</Percent>
<TaxScheme/>
</TaxCategory>
</TaxSubtotal>
</TaxTotal>
<Item>
<Description>KONS. 2H LICHT D37</Description>
<SellersItemIdentification>
<ID>7040237023</ID>
</SellersItemIdentification>
</Item>
<Price>
<PriceAmount currencyID="EUR">3.39</PriceAmount>
<BaseQuantity>1</BaseQuantity>
</Price>
</InvoiceLine>
<InvoiceLine>
<ID>4</ID>
<InvoicedQuantity>10</InvoicedQuantity>
<LineExtensionAmount currencyID="EUR">44.10</LineExtensionAmount>
<OrderLineReference>
<LineID>4</LineID>
<OrderReference>
<ID>351450.27</ID>
</OrderReference>
</OrderLineReference>
<TaxTotal>
<TaxAmount currencyID="EUR">9.26</TaxAmount>
<TaxSubtotal>
<TaxableAmount currencyID="EUR">44.10</TaxableAmount>
<TaxAmount currencyID="EUR">9.26</TaxAmount>
<TaxCategory>
<ID>Excluding</ID>
<Percent>21</Percent>
<TaxScheme/>
</TaxCategory>
</TaxSubtotal>
</TaxTotal>
<Item>
<Description>blabla</Description>
<SellersItemIdentification>
<ID>7041037023</ID>
</SellersItemIdentification>
</Item>
<Price>
<PriceAmount currencyID="EUR">12.37</PriceAmount>
<BaseQuantity>1</BaseQuantity>
</Price>
</InvoiceLine>
<InvoiceLine>
<ID>5</ID>
<InvoicedQuantity>1</InvoicedQuantity>
<LineExtensionAmount currencyID="EUR">25.00</LineExtensionAmount>
<OrderLineReference>
<LineID>6</LineID>
<OrderReference>
<ID>351450.27</ID>
</OrderReference>
</OrderLineReference>
<TaxTotal>
<TaxAmount currencyID="EUR">5.25</TaxAmount>
<TaxSubtotal>
<TaxableAmount currencyID="EUR">25.00</TaxableAmount>
<TaxAmount currencyID="EUR">5.25</TaxAmount>
<TaxCategory>
<ID>Excluding</ID>
<Percent>21</Percent>
<TaxScheme/>
</TaxCategory>
</TaxSubtotal>
</TaxTotal>
<Item>
<Description>blabla</Description>
<SellersItemIdentification>
<ID>VRACHT</ID>
</SellersItemIdentification>
</Item>
<Price>
<PriceAmount currencyID="EUR">25.00</PriceAmount>
<BaseQuantity>1</BaseQuantity>
</Price>
</InvoiceLine>

在这段代码中,最高百分比是 21,所以我只想要 21 作为结果而不是节点中的所有结果..有人可以帮我写代码吗??

C队

我认为你可以在没有扩展功能的情况下做到这一点。您当前的代码似乎表明您可以拥有多个Percent(或者根本没有)。如果是这样,试试这个模板

<xsl:template match="/">
  <xsl:for-each select="/x:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory">
    <xsl:sort select="cbc:Percent * (count(cbc:Percent) = 1) + 21 * (1 - (count(cbc:Percent) = 1))" order="descending" />
    <xsl:if test="position() = 1">
      <xsl:choose>
        <xsl:when test="count(cbc:Percent) = 1">
          <xsl:value-of select="format-number(cbc:Percent,'00')"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="21"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:for-each>
</xsl:template>

如果你只能有零或百分之一,你可以把它简化成这样......

<xsl:sort select="cbc:Percent * count(cbc:Percent) + 21 * count(cbc:Percent)" order="descending" />

而且,当然,如果所有节点总是有一个,Percent你可以这样做......

<xsl:sort select="cbc:Percent" />

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章