2.1. Convert explicitly or implicitly selected ``para`` to a ``simpara``
Prev | 2. Commented examples | Next

### 2.1. Convert explicitly or implicitly selected ``para`` to a ``simpara``

This example can be found in ``XXE_install_dir`/doc/configure/samples2/simpara.xxe`.

    <command name="toSimpara">
      <process showProgress="false">
        <copyDocument selection="true" to="in.xml" />
        <transform stylesheet="simpara.xslt" cacheStylesheet="true"
                   file="in.xml" to="out.xml" />
        <read file="out.xml" encoding="UTF-8" />
      </process>
    </command>

    <command name="paraToSimpara">
      <macro>
        <sequence>
          <command name="selectNode"
                   parameter="ancestorOrSelf[implicitElement] para" />
          <command name="toSimpara" />
          <command name="paste" parameter="to %_" />
        </sequence>
      </macro>
    </command>

    <binding>
      <keyPressed code="ESCAPE" />
      <keyPressed code="S" modifiers="mod" />
      <command name="paraToSimpara" />
    </binding>

In the above example, `simpara.xlst` is simply:

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" encoding="UTF-8" />

    <xsl:template match="para">
      <simpara>
        <xsl:copy-of select="./node()" />
      </simpara>
    </xsl:template>

    </xsl:stylesheet>

### Note

Adding the following generic rule to any XSLT style sheet used in interactive process commands allows to handle the case where the user has selected multiple nodes:

    <xsl:template match="/*[./processing-instruction('select-child-nodes')]">
      <xsl:variable name="pi"
        select="./processing-instruction('select-child-nodes')" />
      <xsl:variable name="first" select="substring-before($pi, '-')" />
      <xsl:variable name="last" select="substring-after($pi, '-')" />

      <c:clipboard
        xmlns:c="http://www.xmlmind.com/xmleditor/namespace/clipboard">

        <xsl:for-each select="child::node()[position() &gt;= $first and
                                            position() &lt;= $last]">
          <xsl:apply-templates select="." />
        </xsl:for-each>

      </c:clipboard>
    </xsl:template>

Prev | Up | Next
2. Commented examples | Home | 2.2. Convert a DocBook document to RTF