[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Process an element depending...

Subject: Re: Process an element depending...
From: Peter Davis <pdavis152@xxxxxxxxx>
Date: Thu, 14 Mar 2002 17:19:21 -0800
Re:  Process an element depending...
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 &#160; 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.