This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: A simple basic question
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: Philip Mak <pmak at aaanime dot net>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 6 May 2002 13:01:57 +0100
- Subject: Re: [xsl] A simple basic question
- Organization: Jeni Tennison Consulting Ltd
- References: <20020506113852.GY30280@lina.aaanime.net>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Philip,
> I looked at various XSL guides, but I still can't figure out how to
> transform this:
>
> <document>
> <paragraph>Here is a <bold>bold</bold> word.</paragraph>
> <paragraph>Here is an <italic>italic</italic> word.</paragraph>
> </document>
>
> into this:
>
> <body>
> <p>Here is a <b>bold</b> word.</p>
> <p>Here is an <i>italic</i> word.</p>
> </document>
>
> The part I have trouble with is the <bold> and <italic>. The thing
> is that they could appear anywhere in the document; they're not part
> of a rigid structure. It seems that when I use <xsl:value-of
> select="paragraph">, the <bold> and <italic> tags inside just get
> stripped out.
Rather than getting the *value of* the paragraph (the value of
something is always just a string; the value of an element is the text
underneath the element), apply templates to it:
<xsl:apply-templates select="paragraph" />
Then have a template for paragraph elements that creates a p element,
and applies template to the content of the paragraph element to create
the content of the p element:
<xsl:template match="paragraph">
<p><xsl:apply-templates /></p>
</xsl:template>
Then have templates for bold and italic elements that likewise create
b and i elements, and apply templates to their content to create the
content of the b and i elements:
<xsl:template match="bold">
<b><xsl:apply-templates /></b>
</xsl:template>
<xsl:template match="italic">
<i><xsl:apply-templates /></i>
</xsl:template>
If you're familiar with CSS, you can think of each XSLT template as
like a CSS rule that says how a particular element (the thing matched
by the template) should be displayed, except that in XSLT the
'display' part is actually the creation of some new content.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list