-1

`

<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>

`

I don't wan to include Mango to report because the status is Delivered to another state with the same ProductCode, Price and Status.

Expected output:

ProductCode Fruit Price 111 Apple 34 222 Papaya 5

LugarLang
  • 5
  • 5
  • Please show the XSLT you are using. Thanks. – potame Nov 13 '15 at 07:59
  • "*because the status is Delivered to another state with the same ProductCode, Price and Status.*" That can be read in number of ways. Please provide a more exact statement of the criteria. – michael.hor257k Nov 13 '15 at 09:59
  • It sounds like you want a way to exclude `Fruit`s that have the same ProductCode, Price, Status, and perhaps Name? Please clarify. Also, if you're using XSLT 2.0, you have options other than `xsl:key`s that might make more sense. – Dan Field Nov 13 '15 at 21:11
  • Thank you all... – LugarLang Jun 28 '17 at 05:35

1 Answers1

0

Something like this:

<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>

The effect of the predicate [last()=1] is to process the group only if its size is 1.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • what is the purpose of '~' in string-join? – LugarLang Nov 28 '15 at 14:56
  • Chosen as an arbitrary separator character that's unlikely to appear in your data. If you were grouping on (First Name, Last Name) then it would ensure that JANE~THORNTON is not grouped with JANET~HORNTON. – Michael Kay Nov 28 '15 at 16:31