我想选择所有后代但"博客"节点.例如,只有子树应出现在输出上.我正在尝试这个xsl代码:
<xsl:template match="rdf:RDF">
<xsl:copy>
<xsl:copy-of select="descendant::*[not(descendant::blog)]"/>
</xsl:copy>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
对于这个xml:
<rdf:RDF>
<profesor rdf:ID="profesor_39">
<nombre rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Augusto</nombre>
</profesor>
<blog rdf:ID="blog_41">
<entradas>
<entrada_blog rdf:ID="entrada_blog_42">
<etiquetas>
<tecnologia rdf:ID="tecnologia_49">
<termino rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Atom</termino>
</tecnologia>
</etiquetas>
<autor>
<alumno rdf:ID="alumno_38">
<nombre rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Jesus</nombre>
</alumno>
</autor>
</entrada_blog>
</entradas>
<autores rdf:resource="#alumno_38"/>
<direccion rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>http://tfg1.unex.es/10comunidad/wordpress/</direccion>
</blog>
</rdf:RDF>
Run Code Online (Sandbox Code Playgroud)
我错过了什么?"博客"节点仍然打印在输出上.谢谢.
这是一个完整的解决方案:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- By default, recursively copy all nodes unchanged -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- But strip out <blog> -->
<xsl:template match="blog"/>
<!-- If you want to strip out just the <blog> start and end tags, use this instead:
<xsl:template match="blog">
<xsl:apply-templates/>
</xsl:template>
-->
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)