This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: following-sibling or grouping maybe
- From: "G. Ken Holman" <gkholman at CraneSoftwrights dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 08 May 2002 08:59:57 -0400
- Subject: Re: [xsl] following-sibling or grouping maybe
- Reply-to: xsl-list at lists dot mulberrytech dot com
At 2002-05-08 12:53 +0300, Matts Isuls wrote:
>I dont
>want to add any more cells to the HTML rows if the current cell's <data> and
><comment>
You were not handling the current cell in your initial attempt.
>or the following cells on the same row are empty.
You were trying here, but you didn't consider white space.
>the XSL below produces this:
>
>1 aa 2 bb 3 4
>1 aa 2 3 4 dd
>
>but i would like it this way:
>
>1 aa 2 bb
>1 aa 2 3 4 dd
You were very close. All I did from your version was consider the
normalized value of the sibling and include a test for the current node.
Normalization removes leading and trailing white space and collapses
consecutive sequences of white space to a single space. This allows one to
test for "no content" when white space isn't significant. Otherwise, white
space is significant without stylesheet commands to prune the source tree.
I hope this helps.
................ Ken
T:\ftemp>type matts.xml
<?xml version="1.0"?>
<table>
<row>
<cell id="1">
<data>aa</data>
<comment></comment>
</cell>
<cell id="2">
<data></data>
<comment>bb</comment>
</cell>
<cell id="3">
<data></data>
<comment></comment>
</cell>
<cell id="4">
<data></data>
<comment></comment>
</cell>
<cell id="5">
<data></data>
<comment></comment>
</cell>
</row>
<row>
<cell id="1">
<data>aa</data>
<comment></comment>
</cell>
<cell id="2">
<data></data>
<comment></comment>
</cell>
<cell id="3">
<data></data>
<comment></comment>
</cell>
<cell id="4">
<data>dd</data>
<comment></comment>
</cell>
<cell id="5">
<data></data>
<comment></comment>
</cell>
</row>
</table>
T:\ftemp>type matts.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<table border="1">
<xsl:for-each select="/table/row">
<tr>
<xsl:for-each select="cell">
<xsl:if test="normalize-space(.)!='' or
following-sibling::*[normalize-space(.)!='']">
<td>
<xsl:value-of select="@id"/><xsl:value-of select="."/>
</td>
</xsl:if>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</html>
</xsl:template>
</xsl:stylesheet>
T:\ftemp>saxon -o matts.out matts.xml matts.xsl
T:\ftemp>type matts.out
<html>
<table border="1">
<tr>
<td>1
aa
</td>
<td>2
bb
</td>
</tr>
<tr>
<td>1
aa
</td>
<td>2
</td>
<td>3
</td>
<td>4
dd
</td>
</tr>
</table>
</html>
T:\ftemp>rem Done!
--
Upcoming: 3-days XSLT/XPath and/or 2-days XSLFO: June 17-21, 2002
- : 3-days XML Information Modeling: July 31-August 2, 2002
G. Ken Holman mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
ISBN 0-13-065196-6 Definitive XSLT and XPath
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1 Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books(electronic, printed),
articles, training(instructor-live,Internet-live,web/CD,licensed)
Next public training: 2002-05-06,07,09,10,13,15,20,
- 06-04,07,10,11,13,14,17,20,07-31,08-05,27,30
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list