Search code examples
javaxmlxsltnodessax

Finding a specific node in xml hierarchy JAVA


I am using SAX to transform an XML document and remove nodes using an xsl:stylesheet (thanks to teppic). I'm not familiar with XML to understand how to edit the document.

xsl:

<!-- Copy -->
<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>

<!-- Strip IMFile elements -->
<xsl:template match="IMFile"/>

This is getting all nodes of IMFile and deleting them perfectly. I now need to search nodes of type: Callout and see if any of their child of VectorNode's value is equal to TypeWinText and if so delete the entire Callout node. If not - do nothing.

Project_Data Version="8.00"> 
<CSMLData> 
<GoProject id="1" version="3.0" > <Project id="2" editRate="30/1" version="3.0" > 
<Timeline id="6" > 
<GenericMixer id="10" name="Unified Mixer"> 
<Tracks> 
<GenericTrack id="11" > 
<Medias> 
<Callout id="91" start="55" duration="20" scalar="1/1" mediaStart="25/1" mediaDuration="20/1" > 
<Attributes> 
<Attribute id="130" name="vectorNode"> 
<VectorNode id="131" kind="TypeWinSVG" > </VectorNode>

Solution

  • Consider adding another empty template to remove Callout based on specific condition:

    <xsl:template match="Callout[descendant::VectorNode/@kind='TypeWinText']"/>