0
我想删除一个节点,但在祖先节点注入内容。这是XML:XSLT删除节点,但保留内容
<w lemma="comment2" type="adv." ana="comment">comment</w>
<name ref="roland"><w lemma="roland" type="nom propre" ana="roland">roland</w></name>
<w lemma="faire" type="vindps3" ana="fyt"><choice><orig>fyt</orig><reg>fist</reg></choice></w>
<name ref="yvon de montauban"><w lemma="yvon" type="nom propre" ana="yvon">yvon</w>
<w lemma="de" type="prép" ana="de">de</w>
我的愿望是删除completedly <reg>
和它的内容,删除标签<choice>
和删除标签<orig>
而是把它的内容到<w>
标签。有人可以帮帮我吗 ?
的XSLT现在是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:output method="xml"/>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:for-each select="./@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="div">
<xsl:element name="{local-name()}">
<xsl:for-each select="./@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="s">
<xsl:element name="{local-name()}">
<xsl:for-each select="./@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="name">
<xsl:element name="{local-name()}">
<xsl:for-each select="./@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="pb">
<xsl:choose>
<xsl:when test="@ed='bnf'">
<xsl:element name="{local-name()}">
<xsl:for-each select="./@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="w">
<xsl:choose>
<xsl:when test="descendant::orig">
<xsl:element name="w">
<xsl:for-each select="./@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:when test="descendant::reg">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:element name="w">
<xsl:for-each select="./@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="choice"/>
<xsl:template match="orig">
<xsl:apply-templates select="*" />
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="reg"/>
</xsl:stylesheet>
谢谢您的帮助:) 米莎
我的愿望是删除completedly REG标签和它的内容,删除选择标签并删除原稿 - 标签,但把它的内容分成w标签。 – Micha
您的XML格式不正确。您尚未提供预期的输出。请更新您的问题。 –