RE: several questions on XML to HTML processing with XSL

Subject: RE: several questions on XML to HTML processing with XSL
From: H.vanderLinden@xxxxxxxxxxxxx
Date: Fri, 09 Jun 2000 16:02:03 +0200

thanks for the anwers, but I'm afraid I haven't been clear enough.
> > 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>

This is similar to what I have except for the <xsl:apply-templates /> part.
This is more detailed with <xsl:call-template...> statements.
I want to get rid of this structure since it involves copying the actual
content of the DIV/LAYER part and
modifications to that part should be carried out twice.

> > 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>.

Ah well, I didn't know about that (thanks for the info) but at the moment
it's not relevant to my problem.
> 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>

The point is I've had my website already set up in HTML with DIV/LAYER and
CSS. Some pages are relatively 'stable' in the fact that the content won't
change very often, but the layout of the main part of the pages 
differs according to the need. Some have two columns others one, some have a
picture to the right some don't etc.
The idea to XML-ify them was that I could use the XML/XSL code I already
have to put the necessary navigation information around the main part (the
actual content) of the page. So instead of defining heaps of XML tags that
will only be used once or twice I would like to put the current HTML-content
between XML-tags and pass it on to the HTML output. Something like this:

<table cellspacing='0' border='0'>
<tr><td><img src='myimage.jpg'></td><td>some text</td></tr>
<!-- some more HTML formatted text -->

The output in the HTML file would be everything between the
<maintext></maintext> tags.
So the <![CDATA[..]]> content would be in the XML file instead of the XSL

> > 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>

This sounds like a good idea. I'll try that.
Some other question came up:

4. How do I declare a variable parametername?

I'd like to do the following, but Saxon returns an errormessage on the
<xsl:with-param> line (invalid $ character).

<xsl:variable name="ParamName">someXMLtag/@someAttribute</xsl:variable>

<xsl:call-template name="SomeTemplateName">
   <xsl:with-param name="$ParamName">whateverValue</xsl:with-param>

How should I do this?

Helma van der Linden
Medical Informatics

 XSL-List info and archive:

Current Thread