RE: [xsl] RE: variable assignment and disable-output-escaping

Subject: RE: [xsl] RE: variable assignment and disable-output-escaping
From: "OHalloran, Martin" <Martin.OHalloran@xxxxxxxxx>
Date: Mon, 11 Apr 2011 12:26:40 -0600
Michael ,
  Thank you for your detailed response .I had tried to pass the Document Node
on my first attempt and then went on to try what I had posted but
when I pass the Document Node .I get a conversion error .

ERROR:  'Invalid conversion from
dElementImpl' to 'node-set'.'
javax.xml.transform.TransformerException: java.lang.RuntimeException: Invalid
nversion from '' to

I also applied the exsl:node-set to the variable but same Exception .
<xsl:for-each select="exsl:node-set($tp)//select/option">

           <xsl:text>Printing value</xsl:text>
           <xsl:value-of select="."/>
           <xsl:value-of select="@value"/>


I have seen a few postings on this error but I have seen no solution .

Thanks again for your help .

-----Original Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
Sent: Monday, April 11, 2011 2:14 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] RE: variable assignment and disable-output-escaping

On 11/04/2011 04:05, OHalloran, Martin wrote:
> Hi thanks for reading .
> I have the following xml which is passed as a parameter to my xsl file for
transformation from a jsp .
> tradingPartnerXML =
>        "<select>"+
>        "<option value='711'>711: Compression Disabled</option>"+
>        "<option value='729'>729: Compression Enable</option>"+
>        "</select>";
It sounds as if you are passing this as a string, not as an XML document.
> when I receive it the tags<   >  are replaced with&lt; and&gt .
That's because no-one has told the XSLT processor that this string is to be
treated as XML. It thinks the "<" and ">" are ordinary characters, and
therefore need to be escaped.
> I then do the following and it looks good  .
> <xsl:message>Trading partner xml is:<xsl:value-of
> select="$tradingPartnerXML"
> disable-output-escaping="yes"/></xsl:message>
The output of xsl:message is very processor dependent, so this doesn't prove
very much; but it's not unreasonable that this should cause the serializer
used by the xsl:message instruction to output "<" as "<"
instead of as "&lt;".
> I then want to create another variable from the contents of the
tradingPartnerXML so I do the following .
> <xsl:variable name="tradingPartner">
>        <xsl:text disable-output-escaping="yes">
>            <xsl:copy-of select="$tradingPartnerXML"/>
>        </xsl:text>
>      </xsl:variable>
This isn't going to work. disable-output-escaping is an instruction to the
serializer, and it only works when you are serializing. (Well, there's more to
it than that. There was an infamous erratum to the XSLT 1.0 specification than
said disable-output-escaping was "sticky", i.e.
if you applied it to a character and held that character in a variable, then
this property of the character would be remembered when the time came to
serialize. However, the property won't affect a test like
(contains($tradingPartner, '>')), and it probably won't be copied when you
copy the variable to another variable. And this erratum was effectively
rescinded in XSLT 2.0).

> Thanks again for you help .If there is another soulution I would like to
hear it .
The answer is perfectly simple: parse the XML before you pass it to the XSLT
processor. Pass it an XML document node, not a string containing lexical XML
with angle brackets.

Michael Kay

This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful.  If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.

Current Thread