I have this style-sheet and It's not working how intended and I am unsure where to go from here.
This is the XML:
<Root>
<CSMLData>
<GoProject>
<Project>
<Timeline>
<GenericMixer>
<Tracks>
<Medias>
<Callout>
<Attributes>
<Attribute>
<Parameter>
<Keyframes>
<Keyframe id="xx" value="Transparent Hotspot"/>
</Keyframes>
</Parameter>
</Attribute>
</Attributes>
</Callout>
</Medias>
</Tracks>
</GenericMixer>
</Timeline>
</Project>
</GoProject>
</CSMLData>
</Root>
There are multiple children of type Keyframes inside Parameter, but only one Keyframe inside Keyframes for each.
This is the style-sheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- Strip IMFile elements -->
<xsl:template match="Callout[descendant::Keyframe/@value='Transparent Hotspot']"/>
</xsl:stylesheet>
The outcome should remove the parent Callout and all of it's children so everything inside Callout if the condition is met should be removed.
It was user error. I was using this this apply the style-sheet using Java. Below is the code that worked for me.
private void removeTransparentHotspots(){
XMLReader readerXML = null;
try {
readerXML = XMLReaderFactory.createXMLReader();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TransformerFactory tf = TransformerFactory.newInstance();
// Load the transformer definition from the file strip.xsl:
InputStream i = MyClass.class.getResourceAsStream("strip.xsl");
Transformer t = null;
try {
t = tf.newTransformer(new SAXSource(readerXML, new InputSource(i)));
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
t.transform(new SAXSource(readerXML, new InputSource(new FileInputStream(getFile()))), new StreamResult(getFile()+"-tmp"));
} catch (FileNotFoundException | TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Once everything is complete, delete old file..
File tempFile = new File(getFile());
tempFile.delete();
// And rename tmp file's name to old file name
File newFile = new File(getFile()+"-tmp");
newFile.renameTo(tempFile);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.