cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Fagerstrom <>
Subject Re: [RT] the quest for the perfect template language
Date Fri, 04 Apr 2003 09:45:28 GMT
Pier Fumagalli wrote:
> But if you asked me about the "perfect template language", it would be a
> some sort of "content aggregator with XPath" generator, where, given the
> following sitemap:
> <map:match pattern="/news/*">
>   <map:generate src="/templates/news.tmpl"/>
>     <map:parameter name="source" value="cocoon:/data/articles/{1}"/>
>     <map:parameter name="topnews" value="cocoon:/data/lists/topnews"/>
>   </map:generate>
>   <map:serialize/>
> </map:match>
> I could write something like:
> <HTML template:article="source:/article">
>   <HEAD>
>      <TITLE>{article:title}</TITLE>
>    </HEAD>
>    <BODY>
>      <H1>{article:title}</H1>
>      <P tmpl:author="{cocoon:/data/authors/{@author}}/author">
>        Author: 
>        <A href="mailto:{author:email}">{author:name}</A>
>      </P>
>      {article:body}
>      <DL>
>        <DT>Other top news from us</DT>
>        <template:foreach context="topnews:/related/articleref">
>          <DL>
>            <A href="/news/{context:@id}">{context:title}</A>
>          </DL>
>        </template:foreach>
>    </BODY>
> </HTML>
<snip>Output from example</snip>
> ... I don't know... Maybe I don't make sense myself, but I'm troubled as I
> know that my graphic team won't pick up XSLT and won't think about the data
> structures, and without that, right now, it's quite hard to get all the
> other advantages of cocoon...

With XSLT and agreagate you could write something like:

<map:match pattern="/news/*">
   <map:aggregate element="page"/>
     <map:part src="cocoon:/data/articles/{1}"/>
     <map:part src="cocoon:/data/authors/{request-param:author}/author"/>
     <map:part src="cocoon:/data/lists/topnews"/>
   <map:transform src="/templates/news.xslt"/>

Here we use a simplified stylesheet

<HTML xmlns:xsl="" version="1.0">
     <TITLE><xsl:value-of select="/page/article/title"/></TITLE>
     <H1><xsl:value-of select="/page/article/title"/></H1>
       <A href="mailto:{/page/author/email}">
         <xsl:value-of select="/page/author/name"/>
     <xsl:copy-of select="/page/article/body"/>
       <DT>Other top news from us</DT>
       <xsl:for-each select="/page/related/articleref">
           <A href="/news/{@id}"><xsl:value-of select="title"/></A>

Thats all, (i didn't get where you get the @author from so I decided 
that it  was from a request param).

And if you instead used a non-xml syntax (e.g. XQuery based) you would 
get something like:

       <A href="mailto:{/page/author/email}">{/page/author/name}</A>
       <DT>Other top news from us</DT>
       for $context in /page/related/articleref
           <A href="/news/{$context/@id}">{$context/title}</A>

Would that be good enogh?

/Daniel Fagerstrom

View raw message