[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: several questions on XML to HTML processing with XSL

Subject: Re: several questions on XML to HTML processing with XSL
From: Warren Hedley <w.hedley@xxxxxxxxxxxxxx>
Date: Fri, 09 Jun 2000 09:37:56 -0400
all attributes xsl div
H.vanderLinden@xxxxxxxxxxxxx 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.