2.1. Convert explicitly or implicitly selected para to a formalpara

<command name="paraToFormalpara">
      <command name="selectNode" 
               parameter="ancestorOrSelf[implicitElement] para" />
      <command name="toFormalpara" />
      <command name="paste" parameter="to %_" />

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

In the above example, toFormalpara.xsl is simply:

<xsl:stylesheet version="1.0"

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

<xsl:template match="/para">
    <xsl:for-each select="@*">

      <xsl:apply-templates select="node()"/>

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


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, '-')" />


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


The above macro may be implemented much more efficiently by replacing the invocation of process command toFormalpara by a script child element of macro. See Example 4.8, “Convert a DocBook 5 para to a formalpara.