構築するためのアプローチとして、次のことを行います。
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="bo[.//bo]">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="boo[not(boo)]">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
これで十分でない場合は、使用できる入力バリアントと、それらをどのように変換するかをより詳細に説明する必要があります。
上記のテンプレートを使用した完全なスタイルシートは
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="bo[.//bo]">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="boo[not(boo)]">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
</xsl:stylesheet>
と変換
<body>
<bo>
<bo>some text</bo>
<bo>
<bo>some other text</bo>
</bo>
<bo>more text</bo>
</bo>
<bo>
<fig/>
</bo>
</body>
の中へ
<body>
<bo>some text</bo>
<bo>some other text</bo>
<bo>more text</bo>
<bo>
<fig/>
</bo>
</body>