RE: [xsl] Newbie: Embedding styles in XML blocks

Subject: RE: [xsl] Newbie: Embedding styles in XML blocks
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Wed, 24 Sep 2003 13:55:41 -0400
[Arne Claassen]
. There's a fairly simple issue i've run into a
> couple of times, which is embedding simple style controls in 
> a paragraph
> of XML data, such as:
> 
> <para>This is an <i>important</i> paragraph</para>
> 

This is one of those cases that is normally simple to handle but exactly
how to do so best depends on the form of your markup and what you expect
out of it.

In your example, you have html elements within a non-html container (the
"para" element).  __If__ that is always going to be the case, you could
do something as simple as this -

<xsl:template match='para'>
	<p><xsl:copy-of select='node() | @*'/></p>
</xsl:template>

This copies  the nodes (and attributes) that are children of the para
element and wraps them all in a p element.  That is what you said you
wanted.  If you know you will have no attributes, you can omit the "|@*"
part.

Chances are, though, that you will sometimes have some html mixed in
with non-html.  The way to handle this again will depend on the design.
Sometimes all that is necessary is to change element names (for example,
from <important> to <strong>.  In that case, use apply-templates and
write a template for each element you wish to include, as Ryan Graham
just suggested.  The drawback is that you have to change your templates
when you add new elements to the source document design.

All this assumes that you want to create html, but you did not actually
say so.  Another approach is to produce xml and to style it in the
browser using css.  This requires that the result be viewed with a
modern browser, but this may be acceptable.

If this is the case, you need do nothing but include the css (or a link
to it) in the stylesheet so it gets written into the result.  Remember,
each element you want to be visible will have to have its own
instructions in the css, and by default everything will be treated as an
inline style (like a "span").  You need to specify the block display
style for each and every block-type element you want to display.

You can see that there is no one answer, but all the bits you need to do
are simple.  If this is not enough help, give us more information.  You
also may want to adjust the design of the source documents to make it
easier to write the stylesheet (e.g., actually use nothing but
(well-formed) html bits within paragraphs, etc.), but as you can see,
that is not really necessary since xslt is so flexible.

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread