Rank: Newbie
Joined: 8/9/2016 Posts: 1
|
Hi, hoping someone is able to help me out. I'm trying to come up with a match template to remove any invoice that has both feetotal = 0 and costtotal =0 and remove the corresponding feesummary, feedetail and cost summary.
I was able create a template match to remove just the parent invoice when criteria is met but not sure how to remove the feesummary, feedetail and cost summary that belong to each invoice.
This is the XML format:
<root> <invoice> <feetotal>100.00</feetotal> <costtotal>0.00</costtotal> </invoice> <invoice> <feetotal>0.00</feetotal> <costtotal>2.00</costtotal> </invoice> <invoice> <feetotal>0.00</feetotal> <costtotal>0.00</costtotal> </invoice> <feesummary> <etc>1</etc> </feesummary> <feedetail> <etc>1</etc> </feedetail> <costsummary> <etc>1</etc> </costsummary> <feesummary> <etc>2</etc> </feesummary> <feedetail> <etc>2</etc> </feedetail> <costsummary> <etc>2</etc> </costsummary> <feesummary> <etc>3</etc> </feesummary> <feedetail> <etc>3</etc> </feedetail> <costsummary> <etc>3</etc> </costsummary> </root>
|
Rank: Member
Joined: 7/23/2008 Posts: 10 Location: Cincinnati
|
There's cleaner ways to do this but the logic is basically the same. You'll have to find the position of the invoices that are all 0s and match taht with the other elements position key.
Code: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:strip-space elements="*"/> <xsl:output indent="yes"/>
<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
<xsl:variable name="zeroInvoice"> <xsl:for-each select="/root/invoice"> <xsl:if test=".[feetotal = 0][costtotal = 0]"> <position> <xsl:value-of select="position()"/> </position> </xsl:if> </xsl:for-each> </xsl:variable>
<xsl:template match="invoice[feetotal = 0][costtotal = 0]"/>
<xsl:template match="feesummary[etc = $zeroInvoice/position]|feedetail[etc = $zeroInvoice/position]|costsummary[etc = $zeroInvoice/position]"/> </xsl:stylesheet>
|