3

I have XML files that hold recordsets where a certain quantity sometimes equals 0. Now those recordsets I have to get rid of. I did the following.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
   
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<!-- delete 0-quantity records -->
<xsl:template match="/ExportData/DataSet/Tables/Table/Rows/R[productQuantityinttrue='0']"/>

</xsl:stylesheet>

It does basically work: it copies everything except the ones with productQuantityinttrue=0. But sometimes there are recordsets deleted that shouldn't be. Now my question is if it would be better to work with a negotiation like

<xsl:template match="/ExportData/DataSet/Tables/Table/Rows/R[not(productQuantityinttrue='0')]"

And then of course I would have to copy those for which this last statement is true. Has anyone ever made experiences with that? I didn't post the XML because it is basically about "to negate or not to negate".

<?xml version="1.0" encoding="UTF-8"?>
<ExportData>
  <TransportHeader>
    <Timestamp>2011-07-28 14:16:49</Timestamp>
    <From>
      <Name>MFES DynamicExport Plugin</Name>
      <Version>1.1.6.95</Version>
   </From>
    <MessageId>a46d4d6d-667e-4e74-b3c5-a6e9ecaeacb1</MessageId>
  </TransportHeader>
  <ExportConfig>
    <DateTimeFormat>yyyy-MM-dd HH:mm:ss</DateTimeFormat>
    <DecimalSymbol>.</DecimalSymbol>
  </ExportConfig>
  <DataSet>LSA_SALES_EXPORT <Tables>
  <Table>MI_Sales <RH>
      <C>companyCodestringtrue</C>
      <C>storeNumstring</C>
      <C>transactionDatedateTime</C>
      <C>transactionQualifierIDint</C>
      <C>transactionQualifierstring</C>
      <C>costCenterNumberstringtrue</C>
      <C>revenueCenterPOSReflongtrue</C>
      <C>menuItemNumberlong</C>
      <C>menuItemNameOnestring</C>
      <C>menuItemNameTwostringtrue</C>
      <C>crossReferenceOnestringtrue</C>
      <C>crossReferenceTwostringtrue</C>
      <C>consumerUnitDescriptionstringtrue</C>
      <C>transactionValueInclVATdecimaltrue</C>
      <C>transactionValueExclVATdecimaltrue</C>
      <C>productQuantityinttrue</C>
      <C>productValueInclVATdecimaltrue</C>
      <C>productValueExclVATdecimaltrue</C>
      <C>discountType01AmountInclVATdecimaltrue</C>
      <C>discountType02AmountInclVATdecimaltrue</C>
      <C>discountType03AmountInclVATdecimaltrue</C>
      <C>discountType04AmountInclVATdecimaltrue</C>
      <C>discountType05AmountInclVATdecimaltrue</C>
      <C>discountType06AmountInclVATdecimaltrue</C>
      <C>discountType07AmountInclVATdecimaltrue</C>
      <C>discountType08AmountInclVATdecimaltrue</C>
      <C>discountType09AmountInclVATdecimaltrue</C>
      <C>discountType10AmountInclVATdecimaltrue</C>
      <C>discountType01AmountExclVATdecimaltrue</C>
      <C>discountType02AmountExclVATdecimaltrue</C>
      <C>discountType03AmountExclVATdecimaltrue</C>
      <C>discountType04AmountExclVATdecimaltrue</C>
      <C>discountType05AmountExclVATdecimaltrue</C>
      <C>discountType06AmountExclVATdecimaltrue</C>
      <C>discountType07AmountExclVATdecimaltrue</C>
      <C>discountType08AmountExclVATdecimaltrue</C>
      <C>discountType09AmountExclVATdecimaltrue</C>
      <C>discountType10AmountExclVATdecimaltrue</C>
      <C>totalAmountDiscountInclVATdecimaltrue</C>
      <C>totalAmountDiscountExclVATdecimaltrue</C>
      <C>totalAmountVATdecimaltrue</C>
      <C>rateAmountVATdecimaltrue</C>
      <C>returnReasonCodestringtrue</C>
      <C>weightdecimaltrue</C>
      <C>detailTypeinttrue</C>
      <C>detailPOSReflong</C>
      <C>menuItemIDlong</C>
    </RH>
    <Rows>
      <R>
        <companyCodestringtrue>111</companyCodestringtrue>
        <storeNumstring>6002</storeNumstring>
        <transactionDatedateTime>2011-07-27 00:00:00</transactionDatedateTime>
        <transactionQualifierIDint>1</transactionQualifierIDint>
        <transactionQualifierstring>Sales</transactionQualifierstring>
        <costCenterNumberstringtrue/>
        <revenueCenterPOSReflongtrue>1000</revenueCenterPOSReflongtrue>
        <menuItemNumberlong>5900003</menuItemNumberlong>
        <menuItemNameOnestring>Exc X Crmy 100g.LSCA</menuItemNameOnestring>
        <menuItemNameTwostringtrue>Exc X Crmy 1.LSCA</menuItemNameTwostringtrue>
        <crossReferenceOnestringtrue>1110</crossReferenceOnestringtrue>
        <crossReferenceTwostringtrue>037466017594</crossReferenceTwostringtrue>
        <consumerUnitDescriptionstringtrue/>
        <transactionValueInclVATdecimaltrue>3.69</transactionValueInclVATdecimaltrue>
        <transactionValueExclVATdecimaltrue>3.69</transactionValueExclVATdecimaltrue>
        <productQuantityinttrue>1</productQuantityinttrue>
        <productValueInclVATdecimaltrue>3.69</productValueInclVATdecimaltrue>
        <productValueExclVATdecimaltrue>3.265487</productValueExclVATdecimaltrue>
        <discountType01AmountInclVATdecimaltrue/>
        <discountType02AmountInclVATdecimaltrue/>
        <discountType03AmountInclVATdecimaltrue/>
        <discountType04AmountInclVATdecimaltrue/>
        <discountType05AmountInclVATdecimaltrue/>
        <discountType06AmountInclVATdecimaltrue/>
        <discountType07AmountInclVATdecimaltrue/>
        <discountType08AmountInclVATdecimaltrue/>
        <discountType09AmountInclVATdecimaltrue/>
        <discountType10AmountInclVATdecimaltrue/>
        <discountType01AmountExclVATdecimaltrue/>
        <discountType02AmountExclVATdecimaltrue/>
        <discountType03AmountExclVATdecimaltrue/>
        <discountType04AmountExclVATdecimaltrue/>
        <discountType05AmountExclVATdecimaltrue/>
        <discountType06AmountExclVATdecimaltrue/>
        <discountType07AmountExclVATdecimaltrue/>
        <discountType08AmountExclVATdecimaltrue/>
        <discountType09AmountExclVATdecimaltrue/>
        <discountType10AmountExclVATdecimaltrue/>
        <totalAmountDiscountInclVATdecimaltrue/>
        <totalAmountDiscountExclVATdecimaltrue/>
        <totalAmountVATdecimaltrue>0</totalAmountVATdecimaltrue>
        <rateAmountVATdecimaltrue>13</rateAmountVATdecimaltrue>
        <returnReasonCodestringtrue/>
        <weightdecimaltrue>0</weightdecimaltrue>
        <detailTypeinttrue>1</detailTypeinttrue>
        <detailPOSReflong>5900003</detailPOSReflong>
        <menuItemIDlong>136577483</menuItemIDlong>
      </R>
      <R>
        <companyCodestringtrue>111</companyCodestringtrue>
        <storeNumstring>6002</storeNumstring>
        <transactionDatedateTime>2011-07-27 00:00:00</transactionDatedateTime>
        <transactionQualifierIDint>1</transactionQualifierIDint>
        <transactionQualifierstring>Sales</transactionQualifierstring>
        <costCenterNumberstringtrue/>
        <revenueCenterPOSReflongtrue>1000</revenueCenterPOSReflongtrue>
        <menuItemNumberlong>5900185</menuItemNumberlong>
        <menuItemNameOnestring>PD MousseHzl140g.LSCA</menuItemNameOnestring>
        <menuItemNameTwostringtrue>PD MousseHzl.LSCA</menuItemNameTwostringtrue>
        <crossReferenceOnestringtrue>428131</crossReferenceOnestringtrue>
        <crossReferenceTwostringtrue>037466083414</crossReferenceTwostringtrue>
        <consumerUnitDescriptionstringtrue/>
        <transactionValueInclVATdecimaltrue>0</transactionValueInclVATdecimaltrue>
        <transactionValueExclVATdecimaltrue>0</transactionValueExclVATdecimaltrue>
        <productQuantityinttrue>0</productQuantityinttrue>
        <productValueInclVATdecimaltrue>4.99</productValueInclVATdecimaltrue>
        <productValueExclVATdecimaltrue>4.415929</productValueExclVATdecimaltrue>
        <discountType01AmountInclVATdecimaltrue/>
        <discountType02AmountInclVATdecimaltrue/>
        <discountType03AmountInclVATdecimaltrue/>
        <discountType04AmountInclVATdecimaltrue/>
        <discountType05AmountInclVATdecimaltrue/>
        <discountType06AmountInclVATdecimaltrue/>
        <discountType07AmountInclVATdecimaltrue/>
        <discountType08AmountInclVATdecimaltrue/>
        <discountType09AmountInclVATdecimaltrue/>
        <discountType10AmountInclVATdecimaltrue/>
        <discountType01AmountExclVATdecimaltrue/>
        <discountType02AmountExclVATdecimaltrue/>
        <discountType03AmountExclVATdecimaltrue/>
        <discountType04AmountExclVATdecimaltrue/>
        <discountType05AmountExclVATdecimaltrue/>
        <discountType06AmountExclVATdecimaltrue/>
        <discountType07AmountExclVATdecimaltrue/>
        <discountType08AmountExclVATdecimaltrue/>
        <discountType09AmountExclVATdecimaltrue/>
        <discountType10AmountExclVATdecimaltrue/>
        <totalAmountDiscountInclVATdecimaltrue/>
        <totalAmountDiscountExclVATdecimaltrue/>
        <totalAmountVATdecimaltrue>0</totalAmountVATdecimaltrue>
        <rateAmountVATdecimaltrue>13</rateAmountVATdecimaltrue>
        <returnReasonCodestringtrue/>
        <weightdecimaltrue>0</weightdecimaltrue>
        <detailTypeinttrue>1</detailTypeinttrue>
        <detailPOSReflong>5900185</detailPOSReflong>
        <menuItemIDlong>136577665</menuItemIDlong>
      </R>
    </Rows>
  </Table>
</Tables>
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Peter
  • 1,786
  • 4
  • 21
  • 40

1 Answers1

3
<!-- delete 0-quantity records --> 

<xsl:template match="/ExportData/DataSet/Tables/Table/Rows/R[productQuantityinttrue='0']"/>

It does basically work: it copies everything except the ones with productQuantityinttrue=0. But sometimes there are recordsets deleted that shouldn't be.

You haven't provided an example to repro this problem.

My guess is that you can fix this issue by using:

<xsl:template match=
   "Rows/R[not(productQuantityinttrue[2]) 
         and 
           productQuantityinttrue='0'
          ]"/>

The expression in the match attribute selects only such .../Rows/R elements that have only a single productQuantityinttrue child and the string value of this only productQuantityinttrue child child is '0'.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • Hello Dimitre, Thank you for your answer. I did provide an example now with 2 recordsets. Of course in reality it is 50 and more sets. I think that also that long path I used might lead to problems. What I don't understand in your question is the "productQuantityinttrue[2]". Do I need that if there is really only one "productQuantityinttrue" per recordset ? – Peter Jul 30 '11 at 16:09
  • @Peter: Thank you for providing an example. However, this example doesn't illustrate your statement that "sometimes there are recordsets deleted that shouldn't be". You need to show an example where such unwanted deletions happen, Also, you need to explain *why* a deleted element shouldn't be deleted. This is necessary in order to modify the match pattern of the empty (deleting) template so that it would match and delete exactly the wanted elements. – Dimitre Novatchev Jul 30 '11 at 16:49
  • Whenever "productQuantityinttrue" is not "0" it should not be deleted. So only the 0-ones have to be deleted. I can't provide an example where unwanted deletions happen because locally (with Oxygen) the output is always okay. Only when running on the server it sometimes occurs. I will definitely shorten the path to "Rows/R..." like you did in your example and check for productQuantityinttrue='0' and see if it happens again. Thank you again for your efforts, Peter – Peter Jul 30 '11 at 18:22