如何在xslt中剪切和粘貼?想我這樣的XML,XSLT -Cut and Paste
<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>
我需要body標籤結束之前創建一個新的節點newnote
和削減和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>
在此先感謝。
我的預期輸出中沒有看到任何''元素,即使據說(根據您的描述文本)生成了該元素。另外,你的意思是*剪切和粘貼*或*複製和粘貼*關於''元素? –
2012-08-04 10:24:12
count節點意味着'notenum',而不是'note'。我需要做剪切和粘貼。請參閱我的輸入和預期輸出。 – dinakar 2012-08-04 10:31:20
我現在看到;弄糊塗了各種''元素被移動或不移動。我已經添加了一個適當的答案,希望能夠滿足你的需求。 –
2012-08-04 10:56:30