【问题标题】:XSLT xsl:key - exclude input from reportXSLT xsl:key - 从报告中排除输入
【发布时间】:2015-11-13 00:52:52
【问题描述】:

`

<Fruits>
    <Fruit>
        <Name>Mango</Name>
        <Price>20</Price>
        <Vendor>Vendor1</Vendor>
        <State>AK</State>
        <Status>Delivered</Status>
        <ProductCode>123</ProductCode>
    </Fruit>
    <Fruit>
        <Name>Apple</Name>
        <Price>34</Price>
        <Vendor>Vendor2</Vendor>
        <State>AS</State>
        <Status>Delivered</Status>
        <ProductCode>111</ProductCode>
    </Fruit>
    <Fruit>
        <Name>Mango</Name>
        <Price>20</Price>
        <Vendor>Vendor3</Vendor>
        <State>FL</State>
        <Status>Delivered</Status>
        <ProductCode>123</ProductCode>
    </Fruit>
    <Fruit>
        <Name>Papaya</Name>
        <Price>5</Price>
        <Vendor>Vendor4</Vendor>
        <State>CA</State>
        <Status>Sold</Status>
        <ProductCode>222</ProductCode>
</Fruit>
</Fruits>

`

我不想在报告中包含 Mango,因为状态是已交付到具有相同 ProductCode、Price 和 Status 的另一个状态。

预期输出:

ProductCode Fruit Price 111 Apple 34 222 Papaya 5

【问题讨论】:

  • 请显示您正在使用的 XSLT。谢谢。
  • "因为状态是已交付到具有相同 ProductCode、Price 和 Status 的另一个状态。" 这可以通过多种方式读取。请提供更准确的标准说明。
  • 听起来您想要一种方法来排除具有相同 ProductCode、Price、Status 和 Name 的 Fruits?请澄清。此外,如果您使用的是 XSLT 2.0,除了xsl:keys 之外,您还有其他可能更有意义的选项。
  • 谢谢大家...

标签: xml xslt xslt-2.0 xslkey


【解决方案1】:

类似这样的:

<xsl:for-each-group select="Fruit" 
  group-by="string-join((ProductGroup, Price, Status), '~')">
  <xsl:apply-templates select="current-group()[last()=1]"/>
</xsl:for-each-group>

谓词[last()=1]的作用是只处理大小为1的组。

【讨论】:

  • 字符串连接中'~'的作用是什么?
  • 被选为不太可能出现在您的数据中的任意分隔符。如果您按 (First Name, Last Name) 分组,那么它将确保 JANE~THORNTON 不与 JANET~HORNTON 分组。
猜你喜欢
  • 1970-01-01
  • 2013-01-18
  • 1970-01-01
  • 1970-01-01
  • 2012-12-28
  • 1970-01-01
  • 1970-01-01
  • 2018-09-22
  • 2011-07-01
相关资源
最近更新 更多