这是一个简单的解决方案,它是面向推送的,不需要<xsl:for-each>
、<xsl:if>
或self::
轴。
当这个 XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="/*">
<document>
<xsl:apply-templates />
</document>
</xsl:template>
<xsl:template match="run/text()">
<para>
<xsl:value-of select="normalize-space()" />
</para>
</xsl:template>
</xsl:stylesheet>
...应用于提供的 XML:
<par>
<run>Line one<break/>
Line two<break/>
</run>
<run>Another para of text<break/>
</run>
<run>3rd para but no break</run>
</par>
...产生了想要的结果:
<document>
<para>Line one</para>
<para>Line two</para>
<para>Another para of text</para>
<para>3rd para but no break</para>
</document>