1. | Spaces turn to %20, how to restore them? |
Easier would be to use the replace() function in XPath 2.0: <xsl:value-of select="replace(text(), '%20', ' ')" /> You only need to use <xsl:analyze-string> if you want to do further manipulation of the matching (or non-matching) strings. | |
2. | Whitespace treatment in 2.0 |
There is one notable exception to this--whitespace character references other than #x20 (space) in attribute values, namely #xD, #xA, and #x9. "Note that if the unnormalized attribute value contains a character reference to a white space character other than space (#x20), the normalized value contains the referenced character itself (#xD, #xA or #x9). This contrasts with the case where the unnormalized value contains a white space character (not a reference), which is replaced with a space character (#x20) in the normalized value..."[1] For example, using a new XSLT 2.0 construct, we can see the difference in behavior very clearly: <xsl:value-of select="(1,2,3)" separator=" "/> will output: 1 2 3 whereas this: <xsl:value-of select="(1,2,3)" separator="
"/> will output: 1 2 3 In the first case, the XML parser reads the attribute value as the space character #x20 (according to attribute value normalization rules), and in the second example the XML parser reads the attribute value as the line feed character #xA. Note that serialization algorithms are also required to make this distinction in order to correctly round-trip attribute values. [1] [1] | |
3. | Not-quite normalize-space() |
a) strip off leading WS, retain trailing WS, and normalize the rest <xsl:variable name="x" select="concat(.,'!@@@!')"/> <xsl:value-of select="substring-before(normalize-space($x),'!@@@!')"/> b) retain leading WS, strip off trailing WS, normalize the rest <xsl:variable name="x" select="concat('!@@@!',.)"/> <xsl:value-of select="substring-after(normalize-space($x),'!@@@!')"/> c) retain leading and trailing WS, normalize the rest <xsl:variable name="x" select="concat('!+++!.,'!@@@!')"/> <xsl:value-of select="substring-after(substring-before(normalize-space($x),'!@@@!'),!+++!')"/> |