This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: several questions on XML to HTML processing with XSL
- To: xsl-list at mulberrytech dot com
- Subject: Re: several questions on XML to HTML processing with XSL
- From: Warren Hedley <w dot hedley at auckland dot ac dot nz>
- Date: Fri, 09 Jun 2000 09:37:56 -0400
- CC: H dot vanderLinden at MI dot UNIMAAS dot NL
- Organization: Department of Engineering Science, The University of Auckland
- References: <6B576313FB1FD311A67400508B440F1201C0BE8A@mail003.unimaas.nl>
- Reply-To: xsl-list at mulberrytech dot com
H.vanderLinden@MI.UNIMAAS.NL wrote:
>
> 1. I want to output <LAYER ID='something'><!-- some HTML goes here
> --></LAYER> when I find the browser is
> Netscape 4+ and <DIV ID='something'><!-- some HTML goes here --></DIV> when
> the browser is Internet Explorer 4+.
<xsl:template match="some_div-like_element">
<xsl:choose>
<xsl:when test="$browser = 'NC4'">
<div ID='{whatever}'>
<xsl:apply-templates />
</div>
</xsl:when>
<xsl:otherwise>
<layer ID='{whatever}'>
<xsl:apply-templates />
</layer>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
> 2. I want to allow (well-formed) HTML in my XML file which I want to output
> as is in my HTML file, how should I go about? E.g. I want this in my XML
> file and out to HTML in the same way:
You've probably got the wrong end of the stick here. If you use the
HTML output method, then a conformant XSLT processor (like Saxon) will
convert your well-formed XML into the abbreviated HTML syntax with which
browsers are familiar.
Putting the following at the top of your stylesheet
<xsl:output method="html">
turns <img src="img.jpg" /> into <img src="img.jpg">
and <br /> into <br>.
If you really need to put some markup directly into your output document
you could consider using CDATA sections, but this is not the "right" way
to do things.
<xsl:text><![CDATA[<IMG src='img.jpg'>]]></xsl:text>
> 3. If I include an HTML tag as valid XML tag in my XML file, how do I output
> all attributes with their values?
Use <xsl:copy-of ... />. You must copy your attributes across before you
start on the element content.
<xsl:template match="table|img|...">
<xsl:copy> <!-- create start tag for current element -->
<xsl:copy-of select="@*" /> <!-- copy attributes -->
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
Hope this helps.
--
Warren Hedley
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list