2016-10-12 10 views
0

docbookを酸素を使用して処理する際に、いくつか変更する必要があります。XSLTを使用してpara要素の後にセクション要素を閉じる必要があります

私の入力XMLファイルには、次のとおりです。私は取得しています

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

<xsl:template match="section"> 
     <section>  
      <xsl:apply-templates select="node()[not(self::section)]"/> 
     </section> 
<xsl:apply-templates select="section"/> 
    </xsl:template> 

<xsl:template match="section/section[para]"> 
<xsl:apply-templates/> 
</xsl:template> 

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

出力は次のとおりです:

<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.</p> 
     </section> 
     <section> 
     <title>Wing Landing Gear</title> 
     </section> 
     <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> 
     <title>Body Landing Gear</title> 
     </section> 
     <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> 

予想される出力XMLニーズとして使用

<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> 
<section><title>Wing Landing Gear</title> 
<section><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><section><title>Body Landing Gear</title> 
<section><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> 
</section></section></section> 

XSL(2.0)になる:

<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.</p> 
     </section> 
     <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></section> 

私のコードとガイドをご覧ください。事前に感謝

+1

[ask]と[mcve]を参照してください。 – Mat

+0

ありがとう。私は将来の使用のために行います –

答えて

2

私は

<xsl:template match="section[not(section/para)]"> 

...それは現在唯一のネストされたセクションなしを対象に1で、あまり一致しているSectionテンプレートマッチングを交換した場合だと思いますが、このXSLT

をお試しください
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 
<xsl:output method="xml" indent="yes" /> 

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

<xsl:template match="section[not(section/para)]"> 
    <section>  
     <xsl:apply-templates select="node()[not(self::section)]"/> 
    </section> 
    <xsl:apply-templates select="section"/> 
</xsl:template> 

<xsl:template match="section/section[para]"> 
    <xsl:apply-templates/> 
</xsl:template> 

<xsl:template match="para"> 
    <p> 
    <xsl:apply-templates/> 
    </p> 
</xsl:template> 
</xsl:stylesheet> 
+0

そのうまくいく@Tim、しかし、このタグを入れている間、名前空間はセクションとタイトルタグに来ています。 –

+0

ありがとうございます。そのうまく動作します。 –

関連する問題