You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Vincent Seet <sl...@singnet.com> on 2003/03/25 15:58:34 UTC

Tables Generation

Hi Gurus,

Need your urgent help. I have a xml document in which the end result is a
table representation of
it in the form of 2 col x n rows. I have no problem generating this using
the example given in the faq but the tricky part is I need to omit certain
child elements in the xml doc. For eg :

<parent>
    <child id="1"/>
   <child id="2"/>
   <child id="3"/>
   <child id="4"/>
   <child id="5"/>
   <child id="6"/>
</parent>

Let's say child id of 2 and 3 are to be omitted to yield a table below :

<table>
    <tr>
    <td>child id 1</td>
    <td>child id 4</td>
    </tr>
    <tr>
    <td>child id 5</td>
    <td>child id 6</td>
    </tr>
</table>

How should I go about doing this? Thanks!

Regards
Vincent



Re: Tables Generation

Posted by Vincent Seet <sl...@singnet.com>.
Hi Kevin,

Thanks for taking the time to read about my problem. In the example given,
the stylesheet will be hardcoded to skip child id of 2 and 3. I have the
following stylesheet using the same xml given earlier. However the template
details will process nodes of child and not matches. Thus, an empty table is
generated. That's is where I am stucked.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output
 indent="yes"
 omit-xml-declaration="no"
 doctype-public="-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
 doctype-system="http://www.wapforum.org/DTD/xhtml-mobile10.dtd"/>

<xsl:template match="/parent">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<body>
<table>
    <xsl:apply-templates select="*[@id != '2' and @id != '3']" mode
="details"/>
</table>
</body>
</html>
</xsl:template>

<xsl:template mode="details" match="*">
<xsl:for-each select="*[position() mod 2 = 1]">
 <tr>
   <xsl:apply-templates mode="col"
      select=".|following-sibling::*[position() &lt; 2]"/>
 </tr>
</xsl:for-each>

</xsl:template>
<xsl:template match="site" mode="col">
 <td align="center">
child id <xsl:value-of select="@id"/>
 </td>
</xsl:template>

</xsl:stylesheet>



Regards
Vincent

----- Original Message -----
From: <kl...@attbi.com>
To: <xa...@xml.apache.org>
Sent: Wednesday, March 26, 2003 3:51 AM
Subject: Re: Tables Generation


> Vincent,
>
> You don't provide enough information about the
> problem. How do you decide which ones are
> omitted? Are "2" and "3" entered as
> parameters, so that it is essentially random?
> Or is there some pattern?
>
> Assuming it is random, you will have to pass
> that information to the "parent" template.
> Then, when using apply-templates to process
> the "child" nodes, construct a select
> statement which excludes "2" and "3".
>
> I know that is vague, but that is the best I
> can do given the limited info.
>
> Kevin
>



Re: Tables Generation

Posted by kl...@attbi.com.
Vincent,

You don't provide enough information about the 
problem. How do you decide which ones are 
omitted? Are "2" and "3" entered as 
parameters, so that it is essentially random? 
Or is there some pattern?

Assuming it is random, you will have to pass 
that information to the "parent" template. 
Then, when using apply-templates to process 
the "child" nodes, construct a select 
statement which excludes "2" and "3".

I know that is vague, but that is the best I 
can do given the limited info.

Kevin