cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Volkm@r" <plsdontre...@arcor.de>
Subject Re: newby Q: how to aggregate source in resource
Date Thu, 19 Aug 2004 09:11:31 GMT
qMax wrote:
> [...]
> More general:
> I need main page template (currently i use XSLT) which uses (and slightly transforms)
> original HTML content and content from some other sources (currently i
> use map:aggregate as input to this XSLT)
> and should produce final HTML with menu and all that stuff.
> 

What about include?

=============================
<map:pipeline>
   <map:match>
     <map:generate src="original XHTML" />
     <map:transform src="include-things.xsl" />
     <map:transform type="cinclude"/>
     <map:transform type="remove-namespace" />
     <map:serialize/>
   </map:match>
</map:pipeline>
=============================

The first transformation "include-things.xsl" would match the places 
where to add additional content.
There are three templates, the first putting link elements into the head 
element, second which adds a menu at the beginning of the body element 
and last which is identical copy of anything else.
Using [local-name] will only be necessary if your original XHTML has a 
namespace.
The output will have an additional namespace that has to be removed in a 
next step.

=============================
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:ci="http://apache.org/cocoon/include/1.0">

   <xsl:template match="*[local-name()='head']">
     <xsl:copy>
       <xsl:apply-templates select="@*|node()"/>
       <ci:include src="cocoon:/ source for navigation toolbar"
                   select="links/*"
                   ns="http://www.w3.org/1999/xhtml"/>
     </xsl:copy>
   </xsl:template>

   <xsl:template match="*[local-name()='body']">
     <xsl:copy>
       <ci:include src="cocoon:/ source-for-menu "/>
       <div id="content">
         <xsl:apply-templates select="@*|node()"/>
       </div>
     </xsl:copy>
   </xsl:template>

   <xsl:template match="@*|node()">
     <xsl:copy>
       <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
   </xsl:template>

</xsl:stylesheet>
=============================

Now remove xmlns:ci="http://apache.org/cocoon/include/1.0" from the output

=============================
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:output method="xml" indent="yes"/>

   <xsl:template match="/|comment()|processing-instruction()">
     <xsl:copy>
     <!-- go process children (applies to root node only) -->
     <xsl:apply-templates/>
     </xsl:copy>
   </xsl:template>

   <xsl:template match="*">
     <!-- Second attribute creating new namespace. -->
     <xsl:element name="{local-name()}"
                  xmlns="http://www.w3.org/1999/xhtml">
       <!-- go process attributes and children -->
       <xsl:apply-templates select="@*|node()"/>
     </xsl:element>
   </xsl:template>

   <xsl:template match="@*">
     <xsl:attribute name="{local-name()}">
       <xsl:value-of select="."/>
     </xsl:attribute>
   </xsl:template>

</xsl:stylesheet>
=============================

-- 
Volkmar W. Pogatzki


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message