Re: [xsl] Stupid newbie question..

Subject: Re: [xsl] Stupid newbie question..
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 18 Oct 2002 15:49:34 -0400
Hi Jordan,

At 02:16 PM 10/18/2002, you wrote:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
 <xsl:output method = "html" encoding="Windows-1252" />

 <xsl:template match="/">
   <xsl:if test="document/description">
    <title><xsl:value-of select="document/description" /></title>

You don't need that xsl:if test; rather, write a template matching "document/description" and output the title element there. If no such node exists, the template won't be matched.

   <xsl:if test="document/content">
    <xsl:apply-templates select="document/content" />

For exactly the same reason, here the test is completely redundant. If document/content does not exist, no templates will be applied, so the apply-templates instruction by itself is sufficient.


 <xsl:template match="document/content">
  <xsl:apply-templates />

 <xsl:template match="module">
  <xsl:apply-templates select="@id" />

So far, so good.

 <xsl:template match="one">
  This is module one.

That template is your problem. You have no element <one>. Rather, you have an attribute named 'id' with *value* one.


<xsl:template match="attribute::id[.='one']">
  This is module one.

Or even

<xsl:template match="attribute::id">
  This is module <xsl:value-of select="."/>.

Abbreviated XPath for "attribute::id" is "@id", which will work as well.

BTW, on this list there are no "stupid newbie questions". Instead, from newbies we have either
(a) very intelligent, probing questions intended to elicit the deep principles of XSL stylesheet design, or
(b) requests for help getting over a hump early on the learning curve, or
(c) requests for help with syntax from people too lazy or confused to look it up

I'd put your question in category (b). Only (c) is less than welcome, and even there people usually get an answer (especially if they're apparently more confused than lazy).

But we do like subject lines that will be informative to someone searching the archive. Here, "can a template match an attribute?" might be better than "Stupid newbie question". :->


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML

XSL-List info and archive:

Current Thread