xsl-list
[Top] [All Lists]

RE: [xsl] generating conditional comment in html output

2011-02-10 03:19:59
Thanks for all replies, not just Ken!

The content which goes between these strings is, at present, valid HTML
which does not require any input from the XML document. But that may change
if I need to do this in more than one location (because it refers to an id
which at the moment can be a fixed value).

<!--[if gte IE 7]>
<style type="text/css">
#static_footer {
   position: fixed;
   bottom: 0;
  { etc. }
}
</style>
<![endif]-->

If I have to extend this (and I suppose that is more likely than not) your
resource looks very useful, Ken, thanks.

Cheers
T




-----Original Message-----
From: G. Ken Holman [mailto:gkholman(_at_)CraneSoftwrights(_dot_)com] 
Sent: Thursday, 10 February 2011 8:36 a.m.
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] generating conditional comment in html output

At 2011-02-10 08:17 +1300, Trevor Nicholls wrote:
I have a stylesheet which has been turning XML into HTML without batting an
eyelid but somebody has requested that the output HTML contain some
conditional styling. This means that at one point in the output I have to
insert the string

  <!--[if gte IE 7]>

and at another point I have to insert the string

  <![endif]-->

I've tried using &lt; in <xsl:text>, using <xsl:value-of> a variable, using
d-o-e, and none of these options seems to work. They either display the
conditional comment in the browser with < and > (and an editor shows the
literal string "& l t ;" in the HTML) or without, or I get errors telling
me
I have malformed code. I'm processing with Saxon in XSL2, and rendering
with
IE7 and IE8.

What is the proper way to do this please? I found many potential answers in
the FAQ but I haven't found one that works :-(

You don't say what you have between those two strings, but 
syntactically the above is a comment and that is created as follows:

<xsl:comment>[if gte IE 7]>



<![endif]<xsl:comment>

Now, if you need markup in-between those two strings, you can't take 
advantage of standard XSLT serialization of tree nodes.

The HTML specification says that a comment starts with "<!--" and 
ends with "-->" and the bit in-between isn't parsed.

You ask for the "proper way to do this", but is the output "proper" 
HTML to begin with?

I hope this helps, but I suspect your requirement may need more.  If 
you have to serialize markup inside of that comment, then either use 
an extension (if provided by your XSLT processor) or use your own 
template rules to reconstitute markup angle brackets manually for 
tree nodes, since you can't use the standard XSLT serialization.

I've done such manual reconstitution of tree nodes as angle brackets 
when embedded OASIS UBL XML instances in PDF XMP metadata as clear 
text.  It can be done, but it is a pain.  The code for serializing 
XML angle brackets from tree nodes can be downloaded from my web site 
in the free resources section since these UBL stylesheets are 
published for anyone to use.  Check the CraneUBL2UNLK-print.xsl 
fragment in this package:

   http://www.CraneSoftwrights.com/resources/ublss/#ubl2-ss

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

--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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