노드를 제거하려고하지만 조상 노드에 콘텐츠를 삽입합니다. 이것은 xml입니다.
<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>
내 소원은 완전히 <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>
도와 주셔서 감사합니다 :) Micha
올바른 형식의 XML 입력이 주어지면 :
<root>
<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>
</name>
</root>
다음 스타일 시트 :
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="choice|orig">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="reg"/>
</xsl:stylesheet>
반환됩니다 :
<?xml version="1.0" encoding="UTF-8"?>
<root>
<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">fyt</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>
</name>
</root>
노트 :
choice
랩퍼는 제거되었다;orig
조상 w
노드 의 내용이되었습니다 .reg
노드가 억제되었습니다.이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다