XSL:XMLタグを削除しますが、コンテンツを保持します
質問
最近、DocBookからDitaに.xmlファイルをいくつか変更しました。変換は大丈夫でしたが、いくつかの望ましくないアーティファクトがあります。私が困惑しているのは、.ditaが再ング化しないということです <para>
DocBookからタグを付け、それを置き換えます <p>
. 。これは大丈夫だと思うでしょうが、これによりXMLがアイテムを表示し、次の行にあると順序付けられたリストを並べ替えます。
1 item One 2 item Two
それ以外の:
1 item One 2 item Two
では、これを変更するにはどうすればよいですか:
<section>
<title>Cool Stuff</title>
<orderedlist>
<listitem>
<para>ItemOne</para>
</listitem>
<listitem>
<para>ItemTwo</para>
</listitem>
</orderedlist>
これに:
<section>
<title>Cool Stuff</title>
<orderedlist>
<listitem>
ItemOne
</listitem>
<listitem>
ItemTwo
</listitem>
</orderedlist>
申し訳ありませんが、質問についてもっと明確にすべきだったはずです。さまざまなレベルの深さにあるダブルメントからすべてのタグを削除する必要がありますが、常に(ローカル)ツリーリスト項目/パラに従います。私はこれに少し新しいですが、docbook2ditaの変換にそれを貼り付けることで、それを間違っていることができました。それはその場所にあることができますか?
解決
このスタイルシートを使用します。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match ="listitem/para">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
ノート: :IDルールを上書きします。 listitem/para
バイパスされます(これにより混合コンテンツが保存されます)
他のヒント
XSLTを使用してDITAファイルを処理できます。 <para>
ノード:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<!-- copy elements and attributes -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- replace para nodes within an orderedlist with their content -->
<xsl:template match ="orderedlist/listitem/para">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
私は同様の問題を抱えていましたが、XSLT 2.x仕様のように常に100%動作するとは限らないQTDomを使用しています。 (ある時点でApache Libraryに切り替えることを考えています...)
対応するクラスを備えたDIVのコードの同等の「リスト項目」を変更したかったのです。
<xsl:for-each select="/orderedlist/lisitem">
<div class="listitem">
<xsl:apply-templates select="node()"/>
</div>
</xsl:for-each>
これにより、リスト項目が削除され、置き換えられますu003Cdiv class="listitem">
次に、テンプレート、あなたが持っているものu003Cpara>、私の場合、タグを含めることができるので、すべてをプレーンテキストに変換する他の2つの例を使用できませんでした。代わりに私はそれを使用しました:
<xsl:template match ="para">
<xsl:copy-of select="node()"/>
</xsl:template>
それは「パラ」タグを削除しますが、すべての子供をそのまま保持します。そのため、段落にはフォーマットを含めることができ、XSLT処理全体で保存されます。