|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] String containing both single and double quotes (apos
I want to hold a string containing both single and double quotes (apos and quot) in a variable. <xsl:variable name="x" select="'...'"/> I enclose the XPath expression in double quotes, hence I'll have to use entity references or numerical character references to refer to that character from within the expression. Correct. I enclose the string in single quotes, hence - I think - I'll have to use entity references or numerical character references to refer to that character from with the string. And this is wrong. <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<!-- quot ist 34 (x22), apos ist 39 (x27) -->
<xsl:variable name="x"
select="'"O'Reilly"'"/><!-- wrong -->
<xsl:template match="/">
<xsl:value-of select="$x"/>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>Trying to think about it a bit more logically, I find that XPath does not require any of < > & to be treated specially, and that both entity references and numerical character references don't have anything to do with XPath - they're XML constructs. So in this example, the XML parser resolves the references and the XPath engine never gets to see them. Instead, it gets to see a syntax error. Is this analysis correct? It seems there is no way to include a single quote within a string that is itself contained in single quotes. Conversely, the same applies for double quotes. This is a bit hard to believe. Is it true? I wish I could use a backslash! Have I missed anything? I see two solutions in XSLT 1.0: * I can write the xsl:variable as an RTF, which offers much better readability. * I can split the string according to whether single or double quotes occur in it and use the XPath 1.0 concat() function to make it whole again. Do I have more options? In 2.0, instead of an RTF, I'd have a temporary tree. What else has changed that is of immediate interest to the problem at hand? Thanks. Michael Ludwig
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








