xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Minchau <minc...@ca.ibm.com>
Subject Re: [Announce] Escaping double quotation marks in XSL
Date Wed, 24 Oct 2007 15:17:46 GMT
This isn't an "[Announce]".    OK, I got that off my chest.

Assuming that you are using Xalan to do your serialization, one of the
fundamental problems you are probably having is that Xalan has decided to
output all attribute values surrounded by double quotation marks, " ,  not
single quotation marks, ' .   That decision is pretty deep in the code.
This way when it encounters a double quote in the value of the attribute
value it will escape it as &quot; (doing its best to retain the validity of
the output being generated.

Of course there are plenty of ways to generate invalid HTML or XML with any
XSLT processor and <![CDATA[ ...    ]]> comes to mind, where you can put
just about anything in there, including unpaired less than signs.

Assuming that you are only interested in stream serialization, have you
thought of doing the serialization yourself for particular elements?  For
example, something like this:

<!-- self serialization of image elements with tag for image done in CDATA,
but delegate attributes serialization -->
<xsl:template match="image">
 <![CDATA[ <image]>><xsl:apply-templates select="@*"/> <![CDATA[ >]>>
</xsl:template>

<!-- handle src attribute of an image element -->
<xsl:template match="image/@src>
<![CDATA[  src=\"]>><value-of select="."><![CDATA[\"]>>
</xsl:template>

I think this needs polishing, but it has hope.

- Brian



                                                                           
             caporale                                                      
             <tranceradi@hotma                                             
             il.com>                                                    To 
                                       general@xml.apache.org              
             10/23/2007 05:20                                           cc 
             PM                                                            
                                                                   Subject 
                                       [Announce] Escaping double          
             Please respond to         quotation marks in XSL              
             general@xml.apach                                             
                   e.org                                                   
                                                                           
                                                                           
                                                                           
                                                                           





I have XSL inside Javascript.  The XML looks like this:
<image>imagename.jpg</image>.  Any time that tag's there, the output should
be &lt;img src=\"imagename.jpg\" / &gt;.  This template works, but it
doesn't escape the quotation marks:

<xsl:template match="image">

<xsl:attribute name="src">
<xsl:apply-templates />
</xsl:attribute>
</img>
</xsl:template>

What do I need to do to escape the quotation marks from that?  I've seen
about 400 examples on-line--none of which actually do what I want.

Thanks,
Joseph Caporale


--
View this message in context:
http://www.nabble.com/Escaping-double-quotation-marks-in-XSL-tf4680435.html#a13373968

Sent from the Apache XML - General mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message