[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Default Rendering of HTML?


Subject: RE: [xsl] Default Rendering of HTML?
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Mon, 22 Nov 2004 11:55:09 -0500

> From: Shawn [mailto:sgrover@xxxxxxxxxxxxxx]
> while researching how to
> handle
> HTML tags in XML, I came across a reference that used xsl:copy-of,
instead
> of
> value-of.  It occurred to me that what I was trying to do was place
the
> entire node into my output, so copy-of was what I should be using.
So, I
> changed the <xsl:value-of select="text"/> line of my XSL to read
> <xsl:copy-of
> select="text"/> - and suddenly my HTML began to work.
>
> I had two nodes that were to get rendered, but the first (which didn't
> contain
> HTML tags) didn't.  I resolved this by removing the <xsl:output> tag I
had
> tried earlier.
>
> So, I have a working solution.  But, I'm not sure if this is going to
be
> suitable in all cases with HTML tags embedded in XML, or if there is a
> better
> way of doing this.  Any suggestions are appreciated.

It seems as if you are not really clear on what you are trying to
accomplish, and that's perhaps why you have been having some trouble.
Apparently, you want to create an html file as the result of your
transformation.  You don't really have to worry about "rendering", just
about producing the html that you intend.

So the first thing is to insert an html element, along with suitable
head and body elements.  Sure, it is legal to omit the html, head, and
even body elements in html, but never mind that, put them in anyway.
Then you will be able to see if you are creating the right structure.
Also, if you include an html element, the processor will realize that
you want output method='html', even if you do not specifically say so.

Then, things get fairly simple.  If your source document has chunks of
working html, insert them into the output using copy-of, as you
discovered.  Where your source document has content that does not fit
that mold, you have to build it up bit by bit with templates.

So a kind of prototypical stylesheet to produce html output could go
like this (omitting some obvious boilerplate) -

<xsl:output method='html'/>
<xsl:template match='/'>
<html>
   <head><title>xxxx</title>
      <xsl:call-template name='style'/>
      <xsl:call-template name='script'/> <!-- if you will have any
javascript --/>
   </head>

   <body>

   </body>
</html>
</xsl:template>

<xsl:template name='style'>
<style type='text/css'>
   /* Put any embedded css style rules here */
</style>
</xsl:template>

Cheers,

Tom P


Current Thread
Keywords