forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gav...." <brightoncomput...@brightontown.com.au>
Subject RE: [jira] Commented: (FOR-834) GenericMarkup strips comments
Date Wed, 19 Apr 2006 11:18:28 GMT


> -----Original Message-----
> From: Thorsten Scherler [mailto:thorsten.scherler@wyona.com]
> Sent: Tuesday, 18 April 2006 10:59 PM
> To: brightoncomputers@brightontown.com.au
> Cc: dev@forrest.apache.org
> Subject: RE: [jira] Commented: (FOR-834) GenericMarkup strips comments
> 
> El mar, 18-04-2006 a las 22:08 +0800, Gav.... escribió:
> >
> > > -----Original Message-----
> > > From: Gavin (JIRA) [mailto:jira@apache.org]
> > > Sent: Tuesday, 18 April 2006 8:30 PM
> > > To: dev@forrest.apache.org
> > > Subject: [jira] Commented: (FOR-834) GenericMarkup strips comments
> > >
> > >     [ http://issues.apache.org/jira/browse/FOR-
> > > 834?page=comments#action_12374923 ]
> > >
> > > Gavin commented on FOR-834:
> > > ---------------------------
> > >
> > > I have an idea that may cure this but not sure of the 'how'.
> > >
> > > What about we create a <comment></comment> element that when processed
> by
> > > genericMarkup.ft , gets converted into
> > > <xsl:comment></xsl:comment>. Then the final output will render
> correctly
> > > into <!-- --> and will work for both comments and SSI commands.?
> > >
> > > So in the theme.fv file we could have :-
> > >
> > > <forrest:contract name="genericMarkup">
> > >             <forrest:property name="genericMarkup">
> > > <hr/>
> > > <comment>This is a comment</comment>
> > >             </forrest:property>
> > >     </forrest:contract>
> > >
> > > Then we transform this in genericMarkup.ft :-
> > >
> > >  <xsl:template match="/">
> > >         <forrest:content>
> > >           <forrest:part>
> > >             <xsl:copy-of select="$genericMarkup/*"/>
> > >           </forrest:part>
> > >         </forrest:content>
> > >       </xsl:template>
> > >
> > > Now somewhere above we get it to check for <comment> and transform it
> into
> > > <xsl:comment> , this is the bit I'm stuck on.
> >
> >
> > Actually now, I have this working - at least I can get the comments and
> > SSI's transformed nicely. I can also then get the rest of the content
> > Transformed correctly without repeating the comments.
> >
> > Last hurdle, ideas welcome, I can not get the comments and the content
> > To mix properly - that is, once I got a comment transformed and then
> > The content, any more comments get ignored.
> >
> > Using <comment>This is a comment</comment> in the theme.fv file, I then
> > Changed the genericMarkup.ft file to read:-
> >
> > <xsl:param name="genericMarkup"/>
> >       <xsl:template match="/">
> >         <forrest:content>
> >           <forrest:part>
> >  <xsl:copy-of select="$genericMarkup/*[not('comment')]"/>
> >  <xsl:comment><xsl:value-of
> select="$genericMarkup/comment"/></xsl:comment>
> >           </forrest:part>
> >         </forrest:content>
> >       </xsl:template>
> >     </xsl:stylesheet>
> >   </forrest:template>
> >
> > Like I say, comments transform nicely, but any html afterwards and any
> > comments afterwards are then ignored. I'm looking at xsl:choose etc
> > But no luck so far. Hope the above hints someone else.
> 
> Nice Gav, very nice.

Nice, but not quite correct ;)

> 
> I have ATM no time need to finish a project, so here the quick idea:
> 
> Instead of using <xsl:copy-of
> select="$genericMarkup/*[not('comment')]"/> ...
> 
> do
> 
> <xsl:apply-templates select="$genericMarkup/*"/>
> 
> and then in templates on their own (!). Replace ... with more
> options/matches.
> 
> <xsl:templates match="content">
>  <xsl:comment><xsl:value-of select="."/></xsl:comment>
> </xsl:templates>
> 
> <xsl:templates match="*|@*|comment()|...">
>  <xsl:copy>
>   <xsl:apply-templates select="*|@*|comment()|..."/>
>  </xsl:copy>
> </xsl:templates>
> 
> HTH

Cool, that helped heaps thanks, I have now cured it. (he says)

Thanks to your direction I now have :-

<xsl:param name="genericMarkup"/>
      <xsl:template match="/">
        <forrest:content>
          <forrest:part>
 <xsl:apply-templates select="$genericMarkup/*"/>
          </forrest:part>
        </forrest:content>
      </xsl:template>

<xsl:template match="comment">
 <xsl:comment><xsl:value-of select="."/></xsl:comment>
</xsl:template>

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

... which works perfectly.

In theme.fv we can have :-

<forrest:contract name="genericMarkup">
            <forrest:property name="genericMarkup">
		    <hr/>
		    <comment>This is a comment</comment>
		    <p>Hello</p>
		    <comment>Another Comment</comment>
		    <h1>Hello</h1>
		    <comment>#include virtual="/filetoinclude.inc"
</comment>
            </forrest:property>
    </forrest:contract>

Which transforms into :-

<hr />
<!--This is a comment-->
<p>Hello</p>
<!--Another Comment-->
<h1>Hello</h1>
<!--#include virtual="/filetoinclude.inc" -->

Obviously - the last line will be parsed with SSI if .html is enabled on the
server to do so. A weird situation isn't it , using a genericMarkup template
To include SSI content! Anyway, the main issue was comments and that is
done.

Is this an acceptable solution, Paul can you test it your end ?

I'll send a patch if all is ok.

I wonder if this solution is useful elsewhere in Forrest (?)


> 
> Thanks Gavin for your constant and active commitment.

No worries. (or as they say in the India call centres - No Issues !)

Gav...

> 
> salu2
> --
> Thorsten Scherler
> COO Spain
> Wyona Inc.  -  Open Source Content Management  -  Apache Lenya
> http://www.wyona.com                   http://lenya.apache.org
> thorsten.scherler@wyona.com                thorsten@apache.org
> 
> 
> 
> 
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.385 / Virus Database: 268.4.3/316 - Release Date: 17/04/2006



Mime
View raw message