2016-09-08 8 views
0

のいくつかのセットにテンプレートを適用するI以下の入力XML文書があります。私が欲しいのxsl:要素

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<book> 
<article> 
<section><title>DESCRIPTION</title> 
<p>The A380 is available with two types of turbofan engines, the 
Rolls-Royce Trent 900 (variants A380-841, −842 and −843F) or the Engine 
Alliance GP7000 (A380-861 and −863F). Noise reduction was an important 
requirement in the A380 design, and particularly affects engine design.</para> 
<para>Landing gears<ul> 
<li><p>Nose Landing Gear</p> 
</li> 
<li><p>Wing Landing Gear (Bogie Type, 4 Wheels - 4 Braked)</p> 
</li> 
<li><p>Body Landing Gear (Bogie Type, 6 Wheels - 4 Braked)</p> 
</li> 
</ul></p> 
<section><title>Wing Landing Gear</title> 
<p>Each wing landing gear has a leg assembly and 
a four-wheel bogie beam. The WLG leg includes a Bogie Trim Actuator 
(BTA) and an oleo-pneumatic shock absorber.</p> 
</section><section><title>Body Landing Gear</title> 
<p>The two body landing gears have a six-wheel bogie 
beam and a leg assembly that includes an oleo- pneumatic shock absorber. 
A two-piece drag-stay assembly mechanically locks the leg in the extended 
position.</p> 
    <fig xml:id="HSXWB-A-79-11-11-00A01-000A-DTRENTXWB-A-00-00-00-01A01-022A-D-fig-0001" label="1"><title>Landing gear</title> 
     <image align="center" fileref="ICN-HSXWB-A-791111-H-F0302-00001-A-001-01"/></fig> 
</section></section></article><book> 

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<book> 
<article> 
    <section><title>DESCRIPTION</title> 
<para>The A380 is available with two types of turbofan engines, the 
Rolls-Royce Trent 900 (variants A380-841, −842 and −843F) or the Engine 
Alliance GP7000 (A380-861 and −863F). Noise reduction was an important 
requirement in the A380 design, and particularly affects engine design.</para> 
<para>Landing gears<itemizedlist> 
<listitem><para>Nose Landing Gear</para> 
</listitem> 
<listitem><para>Wing Landing Gear (Bogie Type, 4 Wheels - 4 Braked)</para> 
</listitem> 
<listitem><para>Body Landing Gear (Bogie Type, 6 Wheels - 4 Braked)</para> 
</listitem> 
</itemizedlist></para> 
<section><title>Wing Landing Gear</title> 
<para>Each wing landing gear has a leg assembly and 
a four-wheel bogie beam. The WLG leg includes a Bogie Trim Actuator 
(BTA) and an oleo-pneumatic shock absorber.</para> 
</section><section><title>Body Landing Gear</title> 
<para>The two body landing gears have a six-wheel bogie 
beam and a leg assembly that includes an oleo- pneumatic shock absorber. 
A two-piece drag-stay assembly mechanically locks the leg in the extended 
position.</para> 
    <figure xml:id="HSXWB-A-79-11-11-00A01-000A-DTRENTXWB-A-00-00-00-01A01-022A-D-fig-0001" label="1"><title>Landing gear</title> 
     <mediaobject><imageobject><imagedata align="center" fileref="ICN-HSXWB-A-791111-H-F0302-00001-A-001-01"/></imageobject></mediaobject> 
     </figure> 
</section></section></article><book> 

私の目標は、に似て変換したXMLで終わることですがsection、title、para、list、figureのセット全体のxsltを書きます。どのように私は単一のxsl:apply-templateでタグ変換のすべてのセットをカバーするために書くことができます。誰か

+0

*すべてのタグセットをカバーするように単一のxsl:apply-templateを記述すると、元の階層構造は失われます。リストされたすべてのノードは兄弟になります。あなたの期待している成果を見ると、それはあなたがしたいことではありません。 –

+0

Martin Honnenありがとうございました。私はこれを試してみます –

答えて

0

はあなたが基本的なビルディングブロックとして恒等変換テンプレートを変換して使用する各要素のテンプレートを書く助けてください:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 

    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="itemizedlist"> 
     <ul> 
      <xsl:apply-templates/> 
     </ul> 
    </xsl:template> 

    <xsl:template match="listitem"> 
     <li> 
      <xsl:apply-templates/> 
     </li> 
    </xsl:template> 

    <xsl:template match="para"> 
     <p> 
      <xsl:apply-templates/> 
     </p> 
    </xsl:template> 
</xsl:transform> 

あなたはfigureのために自分自身をさらにテンプレートを追加することができます。

+0

こんにちはマーティン、あなたの提供されたコードはうまくいきました。私はこれに取り組んでいますが、不要な名前空間の属性が次のような要素になってしまいます。

どのように私はxsltを使用してこれを制御することができます。 。 –

+0

'

'が不要な場合は、XSLTの 'xsl:transform'(または' xsl:stylesheet')ルート要素に 'xmlns =" http://docbook.org/ns/docbook "'を追加してください。 –

+0

Martinに感謝します。今はparaタグで削除されました。しかし、

は削除されません。これで助けてください。 –

関連する問題