cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geissel, Adrian" <adrian.geis...@ecb.int>
Subject RE: [RT] the quest for the perfect template language
Date Thu, 03 Apr 2003 13:33:22 GMT
Hi all, 

Just in case someone objects to the mixing of _stylesheet_ technologies,
here's a way to 
wrap a long element set into a table (row/col) structure. [BTW: - like the
CSS flow, Rob.]

<xsl:variable name="num-cols" select="4"/>

<xsl:template match="fotografie">
  <table>
    <xsl:call-template name="layout-fotos">
      <xsl:with-param name="fotos" select="foto"/>
    </xsl:call-template>
  </table>
</xsl:template>

<xsl:template name="layout-fotos">
<xsl:param name="fotos"/>
  <tr>
      <xsl:for-each select="fotos[position()&lt;$num-cols">
        <td><img src="{@id}"/><br/><xsl:value-of select="."/></td>
      </xsl:for-each>
  </tr>
  <xsl:if test="count(fotos)&gt;$num-cols">
    <xsl:call-template name="layout-fotos">
      <xsl:with-param name="fotos" select="fotos[position()&gt;$num-cols">
    </xsl:call-template>
  </xsl:if>
</xsl:template>

XSLT is declaritive and recursive - and it helps to be wired that way :)

Of course the other advantage (to Rob's future post) is that it's parsable
with any standard(s-compliant) XML parser - therefore includes some choice
and variety, as well as inheriting other properties of well-formedness, etc.


Extensions are getting better with EXSLT.

/Adrian

-----Original Message-----
From: Robert Koberg [mailto:rob@koberg.com]
Sent: Thursday 03 April 2003 15:07
To: cocoon-dev@xml.apache.org
Subject: RE: [RT] the quest for the perfect template language


Hmmm... You seem to be making this much more complex than it needs to be.

Why not do something like this:

XSL:
<xsl:template match="fotografie">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="foto">
  <div class="thumbnail" onclick="expandImage()">
    <div class="imageContainer">    
      <img src="{@id}" class="img"/>
    </div>
    <div class="description">
      <xsl:apply-templates select="."/>
    </div>
  </div>
</xsl:template>

CSS:
.thumbnail {
display:inline;
margin:10px;
}

.imageContainer {
padding:3px;
border:1px solid blue;
}

.img {
width:20px;
height:20px;
}

description {
font-size:80%;
padding:10px;
}

With this you can have you gallery have the columns fit the width of the
(resized) window and they will wrap when necessary. Perhaps I am missing why
you need the complexity?

Best,
-Rob


> -----Original Message-----
> From: Stefano Mazzocchi [mailto:stefano@apache.org]
> Sent: Thursday, April 03, 2003 2:22 AM
> To: cocoon-dev@xml.apache.org
> 
> Steven Noels wrote:
> > On 3/04/2003 8:52 Jeff Turner wrote:
> >
> >> Pity about losing the declarative processing model.
> >
> >
> > Cannot agree more. Declarative is great SoC.
> 
> Get real: what is declarative in
> 
>   <xsl:choose>
>    <xsl:when test="...">
>     <xsl:call-template name="blah">
>      <xsl:with-param name="whatever>
>       <xsl:for-each select="node()">
>        <xsl:value-of select="."/>
>       </xsl:for-each>
>      </xsl:with-param>
>     </xsl:call-template>
>    </xsl:when>
>    <xsl:otherwise>
>     ...
>    </xsl:otherwise>
>   </xsl:choose>
> 
> ?
> 
> Here is the snipped code I had to write a few days ago in order to
> generate a table of picture thumbnails. Input is something like this
> 
>   ...
>   <fotografie>
>    <foto id="1">whatever</foto>
>    <foto id="2">blah</foto>
>   </fotografie>
>   ...
> 
> 
> The stylesheet looks like this:
> 
>    ...
> 
>    <xsl:template match="fotografie">
>     <table class="fotografie">
>      <xsl:call-template name="rowIterator">
>       <xsl:with-param name="row" select="0"/>
>       <xsl:with-param name="rows" select="ceiling(count(//foto) div
> $columns)"/>
>      </xsl:call-template>
>     </table>
>    </xsl:template>
> 
>    <!-- iterates over rows -->
>    <xsl:template name="rowIterator">
>     <xsl:param name="row"/>
>     <xsl:param name="rows"/>
>     <xsl:if test="$row &lt; $rows">
>      <tr valign="top">
>       <xsl:call-template name="columnIterator">
>        <xsl:with-param name="row" select="$row"/>
>        <xsl:with-param name="column" select="0"/>
>       </xsl:call-template>
>      </tr>
>      <xsl:call-template name="rowIterator">
>       <xsl:with-param name="rows" select="$rows"/>
>       <xsl:with-param name="row" select="$row + 1"/>
>      </xsl:call-template>
>     </xsl:if>
>    </xsl:template>
> 
>    <!-- iterates over columns -->
>    <xsl:template name="columnIterator">
>     <xsl:param name="row"/>
>     <xsl:param name="column"/>
>     <xsl:variable name="item" select="($row * $columns) + $column + 1"/>
>     <xsl:if test="$column &lt; $columns">
>      <td align="center" width="{format-number((1 div $columns), '##%')}">
>       <xsl:choose>
>        <xsl:when test="//foto[$item]">
>         <xsl:apply-templates select="//foto[$item]"/>
>        </xsl:when>
>        <xsl:otherwise>
>         <br/>
>        </xsl:otherwise>
>       </xsl:choose>
>      </td>
>      <xsl:call-template name="columnIterator">
>       <xsl:with-param name="row" select="$row"/>
>       <xsl:with-param name="column" select="$column + 1"/>
>      </xsl:call-template>
>     </xsl:if>
>    </xsl:template>



Any e-mail message from the European Central Bank (ECB) is sent in good faith but shall neither
be binding nor construed as constituting a commitment by the ECB except where provided for
in a written agreement.
This e-mail is intended only for the use of the recipient(s) named above. Any unauthorised
disclosure, use or dissemination, either in whole or in part, is prohibited.
If you have received this e-mail in error, please notify the sender immediately via e-mail
and delete this e-mail from your system.


Mime
View raw message