cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Fagerstrom <dani...@nada.kth.se>
Subject Re: [RT] the quest for the perfect template language
Date Fri, 04 Apr 2003 12:17:50 GMT
Pier Fumagalli wrote:
> "Daniel Fagerstrom" <danielf@nada.kth.se> wrote:
>>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>
> 
> 
> No, I can't... You see where do you get the author from? You get it from a
> request parameter. While in my case the author information (or ID) is stored
> in the article original XML data... It would be fair enough if I could
> rewrite it like
> 
> <map:match pattern="/news/*">
>  <map:aggregate element="page"/>
>    <map:part src="cocoon:/data/articles/{1}"/>
>    <map:part 
> src="cocoon:/data/authors/{document(cocoon:/data/articles/{1})/article/autho
> r}"/>
>    <map:part src="cocoon:/data/lists/topnews"/>
>  </map:aggregate>
>  <map:transform src="/templates/news.xslt"/>
>  <map:serialize/>
> </map:match>
> 
> But, darn, that's UGLY! :-(
> 
>     Pier

Ok, I missed that. A new trial:

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

<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>
       <xsl:variable name="author" 
select="document(cocoon:/data/authors/{/page/article/@author}/author)"/>
       Author:
       <A href="mailto:{$author/email}">
         <xsl:value-of select="$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/{@id}"><xsl:value-of select="title"/></A>
         </DL>
       </xsl:for-each>
   </BODY>
</HTML>

This is partly pull driven and quite close to your original template, 
and in a non-xml syntax it would of course look a litle bit nicer. If 
you use the document() function with run time dependent data you can 
forget about cashing, but the same applies to your original formulation. 
If you want cashing I'm afraid that you have to do something like what 
you proposed above.

/Daniel Fagerstrom



Mime
View raw message