【问题标题】:Finding a specific node in xml hierarchy JAVA在xml层次结构JAVA中查找特定节点
【发布时间】:2016-11-23 22:53:30
【问题描述】:

我正在使用 SAX 转换 XML 文档并使用 xsl:stylesheet 删除节点(感谢 teppic)。我不熟悉 XML 以了解如何编辑文档。

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>

【问题讨论】:

    标签: java xml xslt nodes sax


    【解决方案1】:

    考虑添加另一个空模板以根据特定条件删除 Callout

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

    【讨论】:

    • 我很感激!像魅力一样工作!
    【解决方案2】:

    Callout节点在什么位置,能说的更具体点吗?

    要搜索节点是否具有属性 x,您可以执行以下操作:

    <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:apply-templates select="Keyframes"/>
    

    【讨论】:

    • GoProject/Project/Timeline/GenericMixer/Tracks/GenericTrack/Medias/Callout/Attributes/Attribute/VectorNode
    猜你喜欢
    • 2021-09-29
    • 2015-03-24
    • 2019-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多