cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Salvetti <m...@notremanou.net>
Subject Re: modifying the style of required widgets in CForms
Date Wed, 19 Jan 2005 06:38:33 GMT
Thanks a lot for your answers, i've just tried your idea, but i still 
can't get it to work.
Here is what i tried

<xsl:import href="../resources/forms-samples-styling.xsl" />
<xsl:template match="*" mode="custom-styling">
    <xsl:param name="required" />
    <xsl:copy>
        <xsl:if test="$required='true'">
            <xsl:attribute name="class">required-field</xsl:attribute>   
<!-- (visual properties belong in CSS) -->
        </xsl:if>
    </xsl:copy>
</xsl:template>

<xsl:template match="fi:*" mode="common">
    <!-- Apply the default transformation -->
    <xsl:variable name="control">
        <xsl:apply-imports/>
    </xsl:variable>
    <!-- Now apply our styling -->
    <xsl:apply-templates select="exsl:node-set($control)" 
mode="custom-styling">
        <xsl:with-param name="required" value="@required" />
    </xsl:apply-templates>
</xsl:template>

notice the use of match="*" in the custom-styling template because i 
don't really know what's returned by exsl:node-set($control), but i 
guess it must be something like fi:* as not only the input control is 
concerned here, but also select, textarea, etc...
However, if i match
- "*"    i get an empty <span class="forms-field-required"></span> after 
the control (the * is gone somewhere)
- "fi:*" i get the *, but not the <span> tag

and in both cases i don't get the class="required-field" attribute 
inserted on the control

I'm pretty new to xsl, so i'm not sure to understand the functioning of 
this, but i think if the template to be modified is the one spotted 
first (mode="styling", not mode="common"), maybe the second template 
should be <xsl:template match="fi:*" mode="styling">
However, if i try it,  i get the <span 
class="forms-field-required">*</span> correctly, but the fi:styling of 
the control is lost (cols, lines....)

and i still don't get the class="required-field" attribute inserted on 
the control :-\

i'm a bit confused now...

Marc

Mark Lundquist a écrit :

>
> On Jan 18, 2005, at 10:12 AM, Joerg Heinicke wrote:
>
>> On 18.01.2005 13:29, Marc Salvetti wrote:
>>
>>> [...snip]
>>
>>
>> The template for required is a different one:
>>
>>   <!--+
>>       | Common stuff like fi:validation-message, @required.
>>       +-->
>>   <xsl:template match="fi:*" mode="common">
>>     <!-- validation message -->
>>     <xsl:apply-templates select="fi:validation-message"/>
>>     <!-- required mark -->
>>     <xsl:if test="@required='true'">
>>       <span class="forms-field-required"> * </span>
>>     </xsl:if>
>>   </xsl:template>
>
>
> Nope, Marc got it right :-)... The mode="common" template generates 
> the 'annotations', not the control itself.
>
>>
>>> does someone knows of a good technique to do this (if possible 
>>> outside of forms-field-styling.xsl)
>>
>>
>> Write your own stylesheet, import forms-samples-styling.xsl into it 
>> and overload the template for the required attribute.
>>
>> myforms.xsl:
>>
>> <xsl:stylesheet>
>>
>> <xsl:import href="forms-samples-styling.xsl"/>
>>
>> <xsl:template match="fi:*" mode="common">
>>   <!-- validation message -->
>>   <xsl:apply-templates select="fi:validation-message"/>
>>   <!-- required mark -->
>>   <xsl:if test="@required='true'">
>>     <!-- something different here-->
>>   </xsl:if>
>> </xsl:template>
>>
>> </xsl:stylesheet>
>
>
> Yes (except for being the wrong template...  the mode="styling" one is 
> correct).
>
> And if copying the template seems undesirable, one might try injecting 
> the attribute... something like:
>
>     <xsl:import href="forms-samples-styling.xsl" />
>
>     <xsl:template match="input" mode="custom-styling">
>         <xsl:param name="required" />
>         <xsl:copy>
>             <xsl:if test="$required='true'">
>                 <xsl:attribute 
> name="class">required-field</xsl:attribute>   <!-- (visual properties 
> belong in CSS) -->
>             </xsl:if>
>         </xsl:copy>
>     </xsl:template>
>
>     <xsl:template match="fi:*" mode="common">
>         <!-- Apply the default transformation -->
>         <xsl:variable name="control">
>             <xsl:apply-imports/>
>         </xsl:variable>
>         <!-- Now apply our styling -->
>         <xsl:apply-templates select="ex:node-set($control)" 
> mode="custom-styling">
>             <xsl:with-param name="required" value="@required" />
>         </xsl:apply-templates>
>     </xsl:template>
>
> You could enhance this to use different styling for a field that took 
> a validation error (add a parameter to the custom-styling template)...
>
> HTH,
> —ml—
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
>

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


Mime
View raw message