以下是如何做到这一点:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="test">
This is a string <link>http://www.stackoverflow.com</link> and some more stuff here
</xsl:variable>
<xsl:variable name="vTestNodeset" select="document('')/*/xsl:variable[@name='test']"/>
<xsl:variable name="var1" select="string($vTestNodeset/link)"/>
<xsl:variable name="var2">
<xsl:copy-of select="$vTestNodeset/text()"/>
</xsl:variable>
<xsl:template match="/">
"<xsl:value-of select="$var1"/>"
============
"<xsl:value-of select="$var2"/>"
============
"<xsl:value-of select="normalize-space($var2)"/>"
</xsl:template>
</xsl:stylesheet>
当将此转换应用于任何 XML 文档(未使用)时,将产生所需的结果:
"http://www.stackoverflow.com"
============
"
This is a string and some more stuff here
"
============
"This is a string and some more stuff here"