Re: [xsl]How can I choose to ouput different nodeElement....

Subject: Re: [xsl]How can I choose to ouput different nodeElement....
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 29 Dec 2001 18:51:59 -0500
At 2001-12-29 15:39 +0800, dragonjia wrote:
there is something wrong with my XSL:

Since an XSLT stylesheet is an XML document, it must be well formed.


It helps when writing stylesheets to think of elements and attributes as nodes of a node tree and not angle brackets of markup.

Also, you have assigned non-IDable name tokens to your attributes named ID (though I see that without the DTD they aren't typed ID). You could just take advantage of the position of the media child ... but that is another question.

I know I can repeat the whole paragraph in both when and otherwise container.

Or you could assign the table line to a variable and put the variable contents in each:


<xsl:variable name="contents">
<td>
<xsl:value-of select="@id"/>
</td>
<td align="center">
<xsl:value-of select="."/>
</td>
<td align="center">
<xsl:value-of select="@num"/>
</td>
</xsl:variable>
...
<xsl:choose>
<xsl:when test="(@id mod 2)=0" >
        <tr bgcolor="#ffffcc">
<xsl:copy-of select="$contents"/>
       </tr>
</xsl:when>
<xsl:otherwise>
        <tr>
<xsl:copy-of select="$contents"/>
       </tr>
</xsl:otherwise>
</xsl:choose>

Then again, you could just decide on the background colour at the point in time, and not bother with the variable:

<tr>
<xsl:if test="(@id mod 2)=0">
  <xsl:attribute name="bgcolor">#ffffcc</xsl:attribute>
</xsl:if
<td>
<xsl:value-of select="@id"/>
</td>
<td align="center">
<xsl:value-of select="."/>
</td>
<td align="center">
<xsl:value-of select="@num"/>
</td>
</tr>

Depending on what other needs you may have, one of the two above may be better than the other.

I hope this helps.

............................... Ken



--
Training Blitz: 3-days XSLT/XPath, 2-days XSLFO - Feb 18-22, 2002

G. Ken Holman                mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.         http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1               Practical Formatting Using XSLFO
ISBN 0-13-065196-6                        Definitive XSLT & XPath
XSL/XML/DSSSL/SGML/OmniMark services, books(electronic, printed),
articles, training(instructor-live,Internet-live,web/CD,licensed)
Next public training:   2002-01-10,01-11,01-16,01-18,02-11,02-12,
-           02-13,02-15,02-18,02-21,03-11,03-14,03-15,03-18,03-19


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



Current Thread