2016-11-23 91 views
0

我正在使用SAX转换XML文档并使用xsl:stylesheet(谢谢teppic)删除节点。我不熟悉XML以了解如何编辑文档。查找xml层次结构中的特定节点JAVA

的xsl:

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

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

这越来越IMFile的所有节点,并完美地删除它们。我现在需要搜索类型为:Callout的节点,并查看VectorNode的值是否等于TypeWinText,如果是,则删除整个Callout节点。如果不是 - 什么也不做。

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> 

回答

0

<xsl:template match="Keyframes"> 
<xsl:choose> 
     <xsl:when test="Keyframe/@value='x'"> 
       //do what you want for example 
      <xsl:value-of select="Keyframe/@value> 
       // this will print "x" 
     </xsl:when> 
</xsl:choose> 
</xsl:template> 

您可以将基于模板的考虑添加另一个空模板移除标注在特定条件下:

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

我很感激!奇迹般有效! – Torewin

0

标注节点在什么位置,你能更具体吗?

要搜索节点是否有X你可以做类似的属性:由

<xsl:apply-templates select="Keyframes"/> 
+0

GoProject/Project/Ti meline/GenericMixer/Tracks/GenericTrack/Medias/Callout/Attributes/Attribute/VectorNode < - get Attribute“value”= x 需要为每个标注搜索该x值,如果为true,则删除整个标注节点。我会尽快给你的例子一个镜头! – Torewin