我从评论中提出的建议略有改进,并演变成一个完整的片段,可以在以下网址进行测试
this fiddle
例如。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">
<xsl:output indent="yes"/>
<xsl:template match="root">
<xsl:copy>
<xsl:for-each select="tokenize(., ' ')[normalize-space()]"><line><xsl:value-of select="."/></line></xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
和输出
<root>
<line>Line 1</line>
<line>Line 2</line>
<line>Line 3</line>
</root>