Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 29th, 2014, 10:28 AM
Registered User
 
Join Date: Jun 2014
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Question Remove the parent element if child does elements does not exist

Hi Friends,

In the below file, I want to delete/remove the CPT element if the attribute UMProductId has the value "Radiation Therapy".

Code:
<?xml version="1.0" encoding="us-ascii"?>
<AuthBatch SchemaVersion="1.0" InsurerId="123" Sequence="110" CreateDate="2014-07-10T02:45:02.317" AuthorizationCount="3">
    <Authorizations>
        <Authorization EffectiveDate="2014-07-09" Id="12345">
            <CPTs>
                <CPT Sequence="1" UMProductId="Radiation Therapy" ChangeStatus="ADD" ResendIndicator="INITIAL" />
                <CPT Sequence="2" UMProductId="Radiation Therapy" ChangeStatus="ADD" ResendIndicator="INITIAL" />
                <CPT Sequence="3" UMProductId="Radiation Therapy" ChangeStatus="ADD" ResendIndicator="INITIAL" />
            </CPTs>
            <Program Id="46756" Name="test" ChangeStatus="ADD" />
        </Authorization>  
        <Authorization EffectiveDate="2014-07-09" Id="12345">
            <CPTs>
                <CPT Sequence="1" UMProductId="test" ChangeStatus="ADD" ResendIndicator="INITIAL" />
                <CPT Sequence="2" UMProductId="Radiation Therapy" ChangeStatus="ADD" ResendIndicator="INITIAL" />
                <CPT Sequence="3" UMProductId="Radiation Therapy" ChangeStatus="ADD" ResendIndicator="INITIAL" />
            </CPTs>
            <Program Id="46756" Name="test" ChangeStatus="ADD" />
        </Authorization>  
       </Authorizations>
</AuthBatch>
But, in one Authorization, if all the CPT/UMProductId values are "Radiation Therapy" then, i would like to delete the entire Authorization itself.

Below is my XSLT, which is removing CPT elements but not the Authorization:

Code:
<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>
       
    <xsl:template match="AuthBatch/Authorizations/Authorization/CPTs/CPT[@UMProductId='RADIATION THERAPY' or
        @UMProductId='Radiation Therapy']"/>
    
    <xsl:template match="AuthBatch/Authorizations/Authorization[not(CPTs/CPT)]"/>
     
</xsl:stylesheet>
Myoutput:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="us-ascii"?>
<AuthBatch SchemaVersion="1.0" InsurerId="123" Sequence="110" CreateDate="2014-07-10T02:45:02.317" AuthorizationCount="3">
    <Authorizations>
        <Authorization EffectiveDate="2014-07-09" Id="12345">
            <CPTs/>
            <Program Id="46756" Name="test" ChangeStatus="ADD" />
        </Authorization>  
        <Authorization EffectiveDate="2014-07-09" Id="4567">
            <CPTs>
                <CPT Sequence="1" UMProductId="test" ChangeStatus="ADD" ResendIndicator="INITIAL" />
            </CPTs>
            <Program Id="46756" Name="test" ChangeStatus="ADD" />
        </Authorization>  
    </Authorizations>
</AuthBatch>
Expected Output:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="us-ascii"?>
<AuthBatch SchemaVersion="1.0" InsurerId="123" Sequence="110" CreateDate="2014-07-10T02:45:02.317" AuthorizationCount="3">
    <Authorizations>
 
        <Authorization EffectiveDate="2014-07-09" Id="4567">
            <CPTs>
                <CPT Sequence="1" UMProductId="test" ChangeStatus="ADD" ResendIndicator="INITIAL" />
            </CPTs>
            <Program Id="46756" Name="test" ChangeStatus="ADD" />
        </Authorization>  
    </Authorizations>
</AuthBatch>
Please help me. Thanks in advance!!.


Thanks,
Ajay

Last edited by [email protected]; September 30th, 2014 at 06:07 AM.. Reason: Wrong info





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to know whether the father element has child elements or not JohnKiller XSLT 7 October 18th, 2012 09:50 AM
XSLT logic for repeating child elements within parent node Srinibondugula BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 5 November 8th, 2011 12:05 PM
How to remove remove elements deep using xsl Prabeen XSLT 1 May 5th, 2009 12:55 AM
Access specific Element and its Child elements! suersh79 XML 3 November 22nd, 2006 12:58 AM
Accessing a element of parent window in child wind livehed BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 June 28th, 2005 10:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.