3

Docbookセクションノードをトラバースしようとしています。それらの構造は次のとおりです。

<sect1>
   <sect2>
      <sect3>
         <sect4>
            <sect5>
            </sect5>
         </sect4>
      </sect3>
   </sect2>
</sect1>

したがって、sect1にはsect2のみが含まれ、sect2にはsect3のみが含まれます。1つのノード内に複数のサブノードを含めることもできます。たとえば、sect1内の複数のsect2。

プログラム的には、ループがどのセクションにあるかを追跡するためのカウンターを使用して、それらを再帰的に繰り返します。

今回はXSLTを使用してループする必要があります。したがって、XSLTでこれを行うための同等の方法、またはより良い方法はありますか?

編集:私はすでにウィリーによって提案されたのと同様のコードを持っています。そこでは、すべての宗派ノード(sect1からsect5)を指定します。私はそれがそれ自体で宗派ノードを決定することをループする解決策を探しています、そして私はコードを繰り返す必要がありません。Docbookの仕様では、ネストされたノードを5つまでしか許可されていないことを認識しています。

4

2 に答える 2

4

コメントの1つで言うように、{x}に関係なく、すべてのsect {x}ノードに対して同じ処理を実行している場合は、次で十分です。

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match=
     "sect1|sect2|sect3|sect4|sect5">
      <!-- Some processing here -->
      <xsl:apply-templates/>
    </xsl:template>
</xsl:stylesheet>

「sect」{x}という形式の異なる名前を持つさらに多くの要素を同じ方法で処理する必要がある場合(たとえば、xが[1、100]の範囲にある場合)、次を使用できます。

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match=
     "*[starts-with(name(), 'sect')
      and
        substring-after(name(), 'sect') >= 1
      and
        not(substring-after(name(), 'sect') > 101)
       ]">
      <!-- Some processing here -->
      <xsl:apply-templates/>
    </xsl:template>
</xsl:stylesheet>
于 2009-03-18T04:24:52.597 に答える
0
<xsl:template match="sect1">
    <!-- Do stuff -->
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="sect2">
    <!-- Do stuff -->
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="sect3">
    <!-- Do stuff -->
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="sect4">
    <!-- Do stuff -->
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="sect5">
    <!-- Do stuff -->
    <xsl:apply-templates />
</xsl:template>
于 2009-03-18T03:34:22.950 に答える