cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Gianni <s.gia...@thebug.it>
Subject Re: overriding CForms xslt and css?
Date Wed, 05 Apr 2006 12:24:21 GMT
Hi Fernando,
I usually override templates i need to customize in a different XSL that 
includes the default ones.

For example, if I want to be able to specify a fi:styling/@note 
attribute to show a small note under a field label, i can do it this way :

myproject-forms-styling.xsl

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
                xmlns:i18n="http://apache.org/cocoon/i18n/2.1"        
       
                xmlns:bu="http://apache.org/cocoon/browser-update/1.0"
                exclude-result-prefixes="fi">

  <xsl:include 
href="resource://org/apache/cocoon/forms/resources/forms-advanced-field-styling.xsl"/>

  <!-- Location of the resources directory, where JS libs and icons are 
stored -->
  <xsl:param name="resources-uri"/>

  <xsl:template match="fi:*" mode="label">
    <!-- Copy the fi:* mode label template from forms-field-styling.xsl -->
    <xsl:param name="id"/>

    <xsl:variable name="resolvedId">
      <xsl:choose>
        <xsl:when test="$id != ''"><xsl:value-of select="$id"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="concat(@id, 
':input')"/></xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <label for="{$resolvedId}" title="{fi:hint}">
      <xsl:apply-templates select="." mode="css"/>
      <xsl:copy-of select="fi:label/node()"/>
    </label>

    <!-- Add my own part -->
    <xsl:if test="(string(fi:styling/@note) != '') and string(@state) != 
'output'">
      <br/>
      <i><i18n:text><xsl:value-of 
select="fi:styling/@note"/></i18n:text></i>
    </xsl:if>
    <!-- End of my part -->
  </xsl:template>

If could even be easier this way :

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
                xmlns:i18n="http://apache.org/cocoon/i18n/2.1"        
       
                xmlns:bu="http://apache.org/cocoon/browser-update/1.0"
                exclude-result-prefixes="fi">

  <xsl:import 
href="resource://org/apache/cocoon/forms/resources/forms-advanced-field-styling.xsl"/>

  <!-- Location of the resources directory, where JS libs and icons are 
stored -->
  <xsl:param name="resources-uri"/>

  <xsl:template match="fi:*" mode="label">
    <xsl:apply-imports/>
    <!-- Add my own part -->
    <xsl:if test="(string(fi:styling/@note) != '') and string(@state) != 
'output'">
      <br/>
      <i><i18n:text><xsl:value-of 
select="fi:styling/@note"/></i18n:text></i>
    </xsl:if>
    <!-- End of my part -->
  </xsl:template>

But unfortunately this often does not work as expected, because default 
cocoon XSLs are designed to be included and not imported in another 
stylesheet.

Also, mind priorities. If your template is not called when transforming, 
it could be because of XSL priorities, in that case add priority="20" to 
your templates to force them to be at highest priority, for example :

  <xsl:template match="fi:*" mode="label" priority="20">
   ....

Hope this helps,
Simone


Fernando.Matomira@thomson.com wrote:

> I need to provide a different look for the tabs (using images).
>
>  
>
> What is the right way to override some but not all of the CForms xslt 
> and css files?
>
> There is this {$resources-uri} everywhere.
>
>  
>
> Thanks
>
-- 
Simone Gianni

Mime
View raw message