Boopathy Chandran
Boopathy Chandran

Reputation: 19

The two consecutive elements converted into single element using docbook to dita

My Input docbook xml having the below tags:

<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>

I want the output element as

<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>

How i can change the <section><para> into a <p> element by using XSLT. Thanks in advance

Upvotes: 0

Views: 41

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167716

If you use

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

and

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

plus the identity transformation then the para inside of a section nested inside a parent section is transformed into a p replacing the inner section.

So the complete stylesheet is

<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="section/section[para]">
  <xsl:apply-templates/>
</xsl:template>



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

which transforms the input

<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>

into the output

<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>

online at http://xsltransform.net/94AbWAY.

Upvotes: 1

Related Questions