xsl-list
[Top] [All Lists]

RE: output an apostrophe

2002-11-01 12:58:26
[ aruniima.chakrabarti]

but meanwhile I came with the problem that what if I want to 
output the string 
child::*[name()='label']/@val_id
on screen... 

Sometimes the results can depend on the serializer that the xslt
processor uses.  For example, if the serializer normally places double
quotes around an attribute value, then when it encounters double quotes
within an attribute value it has to escape them.  You may have
encountered this behavior.

One way around this can be to use the other type of quote to embed in
your values.  Then the serializer does not need to escape them.  A
smarter serializer might insepct the attribute value first to figure out
what kind of quotes to use to avoid having to escape them.

For example, with my copy of Saxon,  I get these results -

<xsl:template match="/root">
        <element type=' "xxx" '/>
</xsl:template>

Result - 
<Saxon)         <element type=" &#34;xxx&#34; "/>
<Xalan)          <element type=" &quot;xxx&quot; "/>
(MSXSML3) <element type=" &quot;xxx&quot; " />
(XT)               <element type=" &quot;xxx&quot; "/>

<xsl:template match="/root">
        <element type=" 'xxx' "/>
</xsl:template>

Result - 
(Saxon, MSXML3, XALAN,XT) <element type=" 'xxx' "/>

On the other hand, for many or most purposes, it does not matter if the
quotes are escaped.  For example, the following generates the expected
output:

<name select="{&quot;xxx&quot;}"/>

And so does the following:

<xsl:template match="/">
   <name>
        <xsl:value-of select="name(*[name()=&quot;root&quot;])"/>
  </name>
</xsl:template>

This is to be expected since the parser will replace the character
references or entities with their replacement values before the xslt
processor sees them.

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>