xsltでカットアンドペーストする方法は?私のxmlがこのようになっているとしましょう。
<root>
<header>
some nodes
</header>
<body>
<p>
some text
<link>1</link>
<note xml:id="c5-note-0001" numbered="no">text</note>
</p>
<p>
some text
<link>2</link>
<figure>
<note xml:id="c5-note-0003">text</note>
</figure>
<note xml:id="c5-note-0002">text</note>
</p>
<tabular>
<note xml:id="c5-note-0004" numbered="no">text</note>
</tabular>
<p>
some text
<link>3</link>
<notegroup>
<note xml:id="c5-note-0006">text</note>
</notegroup>
<note xml:id="c5-note-0005">text</note>
</p>
<p>
some text
<link>4</link>
<note xml:id="c5-note-0007">text</note>
</p>
</body>
</root>
私の期待する出力は、
<root>
<header>
some nodes
</header>
<body>
<p>
some text
<link>1</link>
<note xml:id="c5-note-0001" numbered="no">text</note>
</p>
<p>
some text
<link>2</link>
<figure>
<note xml:id="c5-note-0003">text</note>
</figure>
<notenum>1</notenum>
</p>
<tabular>
<note xml:id="c5-note-0004" numbered="no">text</note>
</tabular>
<p>
some text
<link>3</link>
<notegroup>
<note xml:id="c5-note-0006">text</note>
</notegroup>
<notenum>2</notenum>
</p>
<p>
some text
<link>4</link>
<notenum>3</notenum>
</p>
<newnote>
<note xml:id="c5-note-0002">text</note>
<note xml:id="c5-note-0005">text</note>
<note xml:id="c5-note-0007">text</note>
</newnote>
</body>
</root>
newnote
bodyタグの終わりの前に新しいノードを作成し、そのノードを切り取って貼り付ける必要があり、その代わりにノードnote
を生成する必要があります。notenum
note
p
これはノード内でのみ行う必要があります。に該当する場合は、note
何tabular
もする必要はfigure
ありnotegroup
ません。
note
次のような属性が含まれている場合はnumbered="no"
、何もする必要はありません。
私は次のxsltを使用しています(使用しているテンプレートの一致を示すためだけに)、
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match ="figure">
some operation
</xsl:template>
<xsl:template match ="tabular">
some operation
</xsl:template>
<xsl:template match ="notegroup">
some operation
</xsl:template>
</xsl:stylesheet>
前もって感謝します。