Re: Writing out '<', not '&lt;'.

Subject: Re: Writing out '<', not '&lt;'.
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 20 Sep 1999 16:39:57 -0400
At 99/09/20 14:26 -0400, Michael.Scepaniak@xxxxxxxxxxxxx wrote:
I'd like to assign the string "<body bgcolor="White">" to an xsl:variable and
then output that variable as part of my HTML output, but I am unable to do it.

Correct ... you are unable to do it because you are attempting to add a string of text to the result tree and text content is, by default, escaped using typical XML and HTML mechanisms.


To get the result you desire, you must add a <body> element node with a bgcolor="White" attribute node to the result tree and not try to effect the result using a string.

Using a result tree template, this would be as easy as:

  <xsl:template match="/">
    <body bgcolor="white">
      <xsl:apply-templates/>
    </body>
  </xsl:template>

Using result tree instructions, this would be:

  <xsl:template match="/">
    <xsl:element name="body">
      <xsl:attribute name="bgcolor">white</xsl:attribute>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

I hope this helps.

.............. Ken

p.s. there *is* a technique to actually emit the "<" character from a string, but that technique is not portable across all XSLT engines because an engine is allowed to not implement the technique ... plus, what you want to do can be done without resorting to the technique.

--
G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Website:  XSL/XML/DSSSL/SGML services, training, libraries, products.
Practical Transformation Using XSLT and XPath      ISBN 1-894049-01-2
Next instructor-led training:  1999-09-24, 1999-11-08, 1999-12-05/06,
                             1999-12-07, 2000-02-27/28, 2000-05-11/12



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


Current Thread