採取以下作爲一種方法的基礎上:
<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>
這感覺是錯誤的方式;在這個例子中,它是被放棄的父元素,而不是孩子。 –