使用docbook转换为dita的两个连续元素转换为单个元素

时间:2016-10-11 12:04:20

标签: xml xslt docbook dita

我的输入docbook xml具有以下标记:

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

如何使用XSLT将<section><para>更改为<p>元素。提前致谢

1 个答案:

答案 0 :(得分:1)

如果您使用

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

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

加上身份转换,然后嵌套在父para内的section内的section转换为替换内p的{​​{1}}。< / p>

所以完整的样式表是

section

转换输入

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

进入输出

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

在线http://xsltransform.net/94AbWAY