This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Process an element depending...
- From: Peter Davis <pdavis152 at attbi dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 14 Mar 2002 17:19:21 -0800
- Subject: Re: [xsl] Process an element depending...
- References: <B8B6A2F5.131B%amujicaj@mi-mail.cl>
- Reply-to: xsl-list at lists dot mulberrytech dot com
You pretty much have two courses of action:
(1) A tag contains four nw, sw, ne, or se tags
(2) it contains text or something else
In the case of (1), you need to output a table with two rows and two columns,
which means one cell per quadrant. In each of the cells, apply-templates
with the tag that goes in that quadrant.
In the case of (2), there are two additional choices:
(2a) if there is anything inside the tag (other tags or non-whitespace text),
then apply-templates on that content.
(2b) Otherwise, output a <br/> or   to make the HTML table happy.
It's actually not that difficult. You just need an <xsl:choose> with those
three choices as the <xsl:when> tests. The code below assumes that the only
elements that contain nw|sw|ne|se are other nw|sw|ne|se tags or the root
document; you should change the template to match all of the elements that
can contain or be contained in nw|sw|ne|se (or just make it match="node()" to
be lazy).
<xsl:template match="/ | nw | sw | ne | se">
<!-- untested -->
<xsl:choose>
<xsl:when test="nw or sw or ne or se">
<table width="100%">
<tr>
<td width="50%">
<xsl:apply-templates select="nw"/>
</td>
<td width="50%">
<xsl:apply-templates select="nw"/>
</td>
</tr>
<tr>
<td width="50%">
<xsl:apply-templates select="sw"/>
</td>
<td width="50%">
<xsl:apply-templates select="se"/>
</td>
</tr>
</table>
</xsl:when>
<xsl:when test="child::* or normalize-space(.)">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<!-- Another option is to just put <br/> at the end of each <td> above,
remove the second <xsl:when>, and change the <br/> here to
<xsl:apply-templates/>. This will make it always output the <br/> in every
<td>, but it is a little easier to generalize if this is not your only
template. -->
<br/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
On Thursday 14 March 2002 14:56, Alvaro Mujica wrote:
> Hi,
> I am transforming a XML document to a HTML document consisting of tables. I
> have my page divided in 4 (nw, ne, sw, se). My tags to divide the page are
> <nw><ne><sw><se>. I also can divide each section into four again using the
> same sequence <nw><ne><sw><se>. Each section should have its physical space
> even if I leave them empty. I don't know how to divide that space depending
> on which level of depth I am.
> For example,if I have this code:
> <nw>
> 1.0
> </nw>
> <ne>
> <nw>2.1</nw> <ne>2.2</ne>
> <sw>2.3</sw> <se></se>
> </ne>
> <sw></sw>
> <se>
> 4.0
> </se>
>
> The output should look something like this (it's just so you get the idea):
> **************************************************
> *1.0 2.1 2.2 *
> * *
> * 2.3 *
> * *
> * *
> * 4.0 *
> * *
> **************************************************
>
> Thank you very much,
> Alvaro Mujica
>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
--
Peter Davis
Necessity is a mother.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list