xsl-list
[Top] [All Lists]

Re: Newbie: Embedding styles in XML blocks

2003-09-24 10:13:49
From: Arne Claassen <xsl(_at_)claassen(_dot_)net>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Date: 24 Sep 2003 09:23:21 -0700
To: xsl list <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: [xsl] Newbie: Embedding styles in XML blocks

I'm relatively new to XSL, trying to ween myself of customer HTML
templating solutions. 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>

Just use "copy-of" instead of "value-of" and your tags will be left as
<i></i>.

There is no such thing as text styling in the proper XSL fashion -- whatever
works best for you in your project is what works. If you did want to give
the element in your XSL a name other than the one you want in the HTML
output, you could. For example, this is one way to turn your <i>'s into
<b>'s.

    <xsl:template match="p">
        <xsl:apply-templates select="./node()"/>
    </xsl:template>
    <xsl:template match="i">
        <xsl:element name="b"><xsl:value-of select="."/></xsl:element>
    </xsl:template>

The question I always ask is whether I'm being more efficient by using an
element I define, or by just putting in some HTML. And efficiency isn't
always about streamlined code -- I'm doing a project now where an end user
with no HTML experience will be updating content that may have embedded
links in the text. In my XML, I used a "link" element with a "url"
attribute, because the user understands those terms already. In the code, it
would have been simpler to use "a" and "href" but I thought that would
increase the likelihood of human error, so I created my own element with
clearer terms. Whatever works best for each project...

-- Brook


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



<Prev in Thread] Current Thread [Next in Thread>