1

XSLT を使用して、既に定義済みの書式設定、つまり外観が個別に定義された構造図を再作成しようとしています。構造は XML を使用して記述されますが、後でライブラリ ( https://github.com/transpect/xml2tex )のforest助けを借りて、ディレクトリ ツリー スタイルのパッケージを使用して LaTeX コードに変換されます。それらは議論の主要部分ではないので、私はそれらをこれ以上詳しく説明しません。xml2texXproc

私が持っているのは、次の形式のサンプル構造です。

<structure>
  <structentry id="1" parent="0" caller="true">Root</structentry>
  <structentry id="2" parent="1" caller="false">Child 1 of ID 1 (Root)</structentry>
  <structentry id="3" parent="1" caller="false">Child 2 of ID 1 (Root)</structentry>
  <structentry id="4" parent="1" caller="false">Child 3 of ID 1 (Root)</structentry>
  <structentry id="5" parent="4" caller="false">Child 1 of ID 4</structentry>
  <structentry id="6" parent="5" caller="false">Child 1 of ID 5</structentry>
</structure>

理想的には、出力は次の形式にする必要があります。

[{Root},fill=white[{Child 1 of ID 1 (Root)}][{Child 2 of ID 1 (Root)}][{Child 3 of ID 1 (Root)}[{Child 1 of ID 4}[{Child 1 of ID 5}]]]]

または読みやすさのために:

[{Root},fill=white
  [{Child 1 of ID 1 (Root)}]
  [{Child 2 of ID 1 (Root)}]
  [{Child 3 of ID 1 (Root)}
    [{Child 1 of ID 4}
      [{Child 1 of ID 5}]
    ]
  ]
]

視覚的には次のようになります。

サンプル構造

したがって、一致するIDを介してノードを親の下に配置しようとしています。つまり、 を持つノードは、 を持つparent='1'ノードの子である必要がありますid='1'

入力 XML でノードを定義するために 'dbk' (DocBook) 名前空間を使用する次の変換があります。私は XML、XSLT、および XPath に非常に慣れていないため、xsl:template match="dbk:structentry". 追加情報が必要な場合は、喜んで更新します。

  <template context="dbk:structure">
    <text>\begin{center}&#xa;</text>
    <xsl:apply-templates select="dbk:caption"/>
    <text>\rule[5pt]{0.8\textwidth}{0.4pt}&#xa;</text>
    <text>&#xa;\begin{forest}</text>
    <xsl:apply-templates select="dbk:structentry"/>
    <text>\end{forest}</text>
    <text>&#xa;\end{center}</text>
  </template>

  <xsl:template match="dbk:caption">
    \textbf{<xsl:value-of select="."/>}&#xa;
  </xsl:template>
  
  <xsl:template match="dbk:structentry">
    <xsl:choose>
    <xsl:when test="@parent eq '0' and @caller eq 'true'">
      [{<xsl:value-of select="."/>},fill=white<xsl:apply-templates select="@parent eq '1'">]
    </xsl:when>
    <xsl:otherwise>
      [{<xsl:value-of select="."/>}]
    </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

アップデート

新しい問題は、チャートの 1 つのルート エントリを別のチャートのルート エントリと区別するにはどうすればよいかということです。2 つの構造の例を次に示します。

構造 1:

<structure>
  <structentry id="1" parent="0" caller="true">Root 1</structentry>
  <structentry id="2" parent="1" caller="false">Child 1 of ID 1 (Root 1)</structentry>
  <structentry id="3" parent="1" caller="false">Child 2 of ID 1 (Root 1)</structentry>
  <structentry id="4" parent="1" caller="false">Child 3 of ID 1 (Root 1)</structentry>
  <structentry id="5" parent="4" caller="false">Child 1 of ID 4</structentry>
  <structentry id="6" parent="5" caller="false">Child 1 of ID 5</structentry>
</structure>

構造 2:

<structure>
  <structentry id="7" parent="0" caller="true">Root 2</structentry>
  <structentry id="8" parent="7" caller="false">Child 1 of ID 7 (Root 2)</structentry>
  <structentry id="9" parent="7" caller="false">Child 2 of ID 7 (Root 2)</structentry>
  <structentry id="10" parent="7" caller="false">Child 3 of ID 7 (Root 2)</structentry>
  <structentry id="11" parent="10" caller="false">Child 1 of ID 10</structentry>
  <structentry id="12" parent="11" caller="false">Child 1 of ID 11</structentry>
</structure>
4

1 に答える 1