1

最近、いくつかの.xmlファイルをdocbookからditaに変更しました。変換は正常に行われましたが、不要なアーティファクトがいくつかあります。私が困惑しているのは、.ditaがdocbookの<para>タグを認識せず、.ditaに置き換えていること<p>です。これは問題ないと思いますが、これにより、XMLは次の行にあるものとしてアイテムと順序付きリストを表示します。

1
 アイテム1
2
 アイテム2

それ以外の:

1アイテム1
2項目2

だから私はこれをどのように変更しますか:

<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>

申し訳ありませんが、質問をもっと明確にすべきでした。さまざまなレベルの深さのタグをすべて削除する必要がありますが、常に(ローカル)ツリーのlistitem/paraに従います。私はこれに少し慣れていませんが、docbook2ditaトランスフォーメーションに追加することで、間違っている可能性があります。その場所にあることができますか?

4

3 に答える 3

5

私はこのスタイルシートを使用します:

<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>

: アイデンティティ ルールを上書きします。listitem/paraバイパスされます (これにより混合コンテンツが保持されます)

于 2010-10-12T20:52:02.780 に答える
3

<para>ノードを除外する XSLT を使用して、dita ファイルを処理できます。

<?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>
于 2010-10-12T20:43:14.317 に答える
0

同様の問題がありましたが、XSLT 2.x 仕様のように常に 100% 動作するとは限らない QtDom を使用しています。(いつかApacheライブラリに切り替えようと思っています...)

コード内の対応するクラスを持つ div 内の同等の「listitem」を変更したかったのです。

<xsl:for-each select="/orderedlist/lisitem">
  <div class="listitem">
    <xsl:apply-templates select="node()"/>
  </div>
</xsl:for-each>

これにより、listitem が削除され、<div class="listitem"> に置き換えられます。

次に、私の場合は <para> にあるテンプレートにタグを含めることができるため、すべてをプレーンテキストに変換する他の 2 つの例を使用できませんでした。代わりに私はそれを使用しました:

<xsl:template match ="para">
  <xsl:copy-of select="node()"/>
</xsl:template>

これにより、「para」タグが削除されますが、すべての子はそのまま保持されます。そのため、段落に書式を含めることができ、XSLT 処理全体で保持されます。

于 2014-01-10T02:09:27.107 に答える