Pier Fumagalli wrote:
<snip/>
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/[EMAIL PROTECTED]/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:aggregate>
  <map:transform src="/templates/news.xslt"/>
  <map:serialize/>
</map:match>

Here we use a simplified stylesheet http://www.w3.org/TR/xslt#result-element-stylesheet

<HTML xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
  <HEAD>
    <TITLE><xsl:value-of select="/page/article/title"/></TITLE>
  </HEAD>
  <BODY>
    <H1><xsl:value-of select="/page/article/title"/></H1>
    <P>
      Author:
      <A href="mailto:{/page/author/email}";>
        <xsl:value-of select="/page/author/name"/>
      </A>
    </P>
    <xsl:copy-of select="/page/article/body"/>
    <DL>
      <DT>Other top news from us</DT>
      <xsl:for-each select="/page/related/articleref">
        <DL>
          <A href="/news/[EMAIL PROTECTED]"><xsl:value-of select="title"/></A>
        </DL>
      </xsl::for-each>
  </BODY>
</HTML>

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:

<HTML>
  <HEAD>
    <TITLE>{/page/article/title}</TITLE>
  </HEAD>
  <BODY>
    <H1>{/page/article/title}</H1>
    <P>
      Author:
      <A href="mailto:{/page/author/email}";>{/page/author/name}</A>
    </P>
    {/page/article/body}
    <DL>
      <DT>Other top news from us</DT>
      for $context in /page/related/articleref
      return
        <DL>
          <A href="/news/{$context/@id}">{$context/title}</A>
        </DL>
  </BODY>
</HTML>

Would that be good enogh?

/Daniel Fagerstrom




Reply via email to