2016-10-12 7 views
0

docbook에서 산소를 사용하여 프로세스를 수행하는 동안 일부를 변경해야합니다.XSLT를 사용하여 para 요소 뒤에 섹션 요소를 닫아야합니다.

내 입력 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) : 내가 갖는

<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> 
     <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)]"> 

이 XSLT를 시도 ... 중첩 된 부분이없는 하나를 대상으로 하나, 그것은 현재 너무 많이 일치한다 Section 일치하는 템플릿을 대체하는 경우라고 생각

<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

감사합니다. 잘 작동합니다. –