IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

template match to remove specific parents Options · View
mboaler
Posted: Tuesday, August 9, 2016 6:59:14 PM
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>
iceandrews
Posted: Friday, December 23, 2016 4:20:19 PM
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>
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.