以下 XSLT 样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:strip-space elements="*"/>
<xsl:template match="node">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="par">
<p>
<xsl:apply-templates />
</p>
</xsl:template>
<xsl:template match="text()">
<span>
<xsl:value-of select="normalize-space(.)"/>
</span>
</xsl:template>
<xsl:template match="bold/text()">
<span class="bolder">
<xsl:value-of select="normalize-space(.)"/>
</span>
</xsl:template>
</xsl:stylesheet>
当应用于此输入 XML 时:
<node>
<par>
Lorem ipsum dolor <bold>sit</bold> amet, consectetur adipiscing elit.
</par>
</node>
产生以下输出:
<p>
<span>Lorem ipsum dolor</span>
<span class="bolder">sit</span>
<span>amet, consectetur adipiscing elit.</span>
</p>