Mailing List Archive

Need help on patching forrest
Hi rangers...

I wonder whether someone can give me some help on applying a patch to
forrest (html-to-document.xsl) to allow for something like

<ul class='myul'>
...
</ul>

or

<ul id='myul'>
...
</ul>

together with some css applied to that element.

The CSS is no problem, I am now much more familiar with that (after
reading Andy Budd's) very good book about CSS-mastery...

My problem is XSL, since I have not yet the time to dive into XSL.

I changed the file html-to-document.xsl for the ul-element to allow for
the class (see below), the id is not tested but maybe of interest in the
future.

My questions are:
1. How can I avoid to make changes always in the installation of forrest?
Can I use a project-specific local html-to-document.xsl-file instead?

2. Is the way I have done it the preferable way?
Normally if writing code (python for me) I would prefere to write a
function since the core choose-function is repeated twice here.

3. In addition, since this problem will reappear for a lot of elements
again and again a more general solution could be better! Any hints?

4. As I have several of these changes and some improvements done here it
would be nice if I could provide these to the main trunk.
How should I proceed?


Actually we are using forrest 0.8 but I can easily add 0.9dev to my path.

Here is the change:
Adding an extra 'choose' let me allow for the class in ul...
---------------------
<xsl:template match="ul">
<xsl:choose>
<xsl:when test="name(..)='p'">
<xsl:text disable-output-escaping="yes"><![CDATA[</p>]]></xsl:text>
<xsl:choose>
<xsl:when test="@class">
<ul>
<xsl:attribute name="class"><xsl:value-of
select="@class"/></xsl:attribute>
<xsl:apply-templates/>
</ul>
</xsl:when>
<xsl:otherwise>
<ul>
<xsl:apply-templates/>
</ul>
</xsl:otherwise>
</xsl:choose>
<xsl:text disable-output-escaping="yes"><![CDATA[<p>]]></xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="@class">
<ul>
<xsl:attribute name="class"><xsl:value-of
select="@class"/></xsl:attribute>
<xsl:apply-templates/>
</ul>
</xsl:when>
<xsl:otherwise>
<ul>
<xsl:apply-templates/>
</ul>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


Many Thanks

Thomas
Re: Need help on patching forrest [ In reply to ]
On Thu, 2007-11-08 at 09:49 +0100, EMMEL Thomas wrote:
> Hi rangers...
>
> I wonder whether someone can give me some help on applying a patch to
> forrest (html-to-document.xsl) to allow for something like
>
> <ul class='myul'>
> ...
> </ul>
>
> or
>
> <ul id='myul'>
> ...
> </ul>
>
> together with some css applied to that element.
>
> The CSS is no problem, I am now much more familiar with that (after
> reading Andy Budd's) very good book about CSS-mastery...
>
> My problem is XSL, since I have not yet the time to dive into XSL.
>
> I changed the file html-to-document.xsl for the ul-element to allow for
> the class (see below), the id is not tested but maybe of interest in the
> future.
>
> My questions are:
> 1. How can I avoid to make changes always in the installation of forrest?
> Can I use a project-specific local html-to-document.xsl-file instead?
>

Yes, you can. http://forrest.apache.org/docs_0_80/locationmap.html


In your project locationmap you need to implement the match
<match pattern="transform.html.document"> and point to your custom
implementation.

> 2. Is the way I have done it the preferable way?
> Normally if writing code (python for me) I would prefere to write a
> function since the core choose-function is repeated twice here.

I have to admit that the 2 choose functions seem to do exactly the same.

> 3. In addition, since this problem will reappear for a lot of elements
> again and again a more general solution could be better! Any hints?
>

Not sure what you mean.

> 4. As I have several of these changes and some improvements done here it
> would be nice if I could provide these to the main trunk.
> How should I proceed?
>

http://forrest.apache.org/contrib.html

HTH

salu2

>
> Actually we are using forrest 0.8 but I can easily add 0.9dev to my path.
>
> Here is the change:
> Adding an extra 'choose' let me allow for the class in ul...
> ---------------------
> <xsl:template match="ul">
> <xsl:choose>
> <xsl:when test="name(..)='p'">
> <xsl:text disable-output-escaping="yes"><![CDATA[</p>]]></xsl:text>
> <xsl:choose>
> <xsl:when test="@class">
> <ul>
> <xsl:attribute name="class"><xsl:value-of
> select="@class"/></xsl:attribute>
> <xsl:apply-templates/>
> </ul>
> </xsl:when>
> <xsl:otherwise>
> <ul>
> <xsl:apply-templates/>
> </ul>
> </xsl:otherwise>
> </xsl:choose>
> <xsl:text disable-output-escaping="yes"><![CDATA[<p>]]></xsl:text>
> </xsl:when>
> <xsl:otherwise>
> <xsl:choose>
> <xsl:when test="@class">
> <ul>
> <xsl:attribute name="class"><xsl:value-of
> select="@class"/></xsl:attribute>
> <xsl:apply-templates/>
> </ul>
> </xsl:when>
> <xsl:otherwise>
> <ul>
> <xsl:apply-templates/>
> </ul>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
>
> Many Thanks
>
> Thomas
--
Thorsten Scherler thorsten.at.apache.org
Open Source Java consulting, training and solutions
Re: Need help on patching forrest [ In reply to ]
Thorsten,

Fine, at least I have a starting point, however the documenation is very
confusing in this area for a beginner in XSL, Cocoon etc....

I have some small annotations/questions;
Thorsten Scherler schrieb:
> On Thu, 2007-11-08 at 09:49 +0100, EMMEL Thomas wrote:
...
>>
>> My questions are:
>> 1. How can I avoid to make changes always in the installation of forrest?
>> Can I use a project-specific local html-to-document.xsl-file instead?
>>
>
> Yes, you can. http://forrest.apache.org/docs_0_80/locationmap.html
>
>
> In your project locationmap you need to implement the match
> <match pattern="transform.html.document"> and point to your custom
> implementation.

In the project locationmap.xml this is working:

<match pattern="transform.html.document">
<location
src="{properties:skins-dir}/../resources/stylesheets/html-to-document.xsl"/>
</match>

but this not:

<match pattern="transform.html.document">
<location
src="{properties:stylesheets-dir}/html-to-document.xsl"/>
</match>

which should be the same, however the variables used here are somewhat
different from those used in forrest.properties.
Is there a document from which one can see where a variable is valid and
how to call it?


>
>> 2. Is the way I have done it the preferable way?
>> Normally if writing code (python for me) I would prefere to write a
>> function since the core choose-function is repeated twice here.
>
> I have to admit that the 2 choose functions seem to do exactly the same.
>
(..)

>> 3. In addition, since this problem will reappear for a lot of elements
>> again and again a more general solution could be better! Any hints?
>>
>
> Not sure what you mean.

The same can happen for <ol>-elements etc. Thus adding a more general
'functions' to be called from each of these elements wold be nice.
Again, excuse me for these questions since I am starting with XSL...

>
>> 4. As I have several of these changes and some improvements done here it
>> would be nice if I could provide these to the main trunk.
>> How should I proceed?
>>
>
> http://forrest.apache.org/contrib.html
>
> HTH

I will see what I can do!

>

Thomas