You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@forrest.apache.org by Victor Okunev <ve...@gmail.com> on 2006/02/12 09:53:34 UTC

XSL transformation as part of the page content?

Hi All,

I have an XSLT style sheet that I use to generate an HTML table. Is it
possible with Forrest v0.7 to perform the transformation as part of
the site build and include the results under a document's section?
Here is a pseudo code that kind of illustrates what I am after:

index.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright....
-->
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN"
"http://forrest.apache.org/dtd/document-v20.dtd">
<document>
  <header>
    <title>Page Title</title>
  </header>
  <body>
    <section id="sectionid">
      <title>Section Title</title>
      <transform src="data.xml" stylesheet="table.xsl"/>
    </section>
  </body>
</document>

Thank you,

Victor

Re: XSL transformation as part of the page content?

Posted by Ross Gardler <rg...@apache.org>.
Victor Okunev wrote:
> Hi All,
> 
> I have an XSLT style sheet that I use to generate an HTML table. Is it
> possible with Forrest v0.7 to perform the transformation as part of
> the site build and include the results under a document's section?
> Here is a pseudo code that kind of illustrates what I am after:
> 
> index.xml
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!--
>   Copyright....
> -->
> <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN"
> "http://forrest.apache.org/dtd/document-v20.dtd">
> <document>
>   <header>
>     <title>Page Title</title>
>   </header>
>   <body>
>     <section id="sectionid">
>       <title>Section Title</title>
>       <transform src="data.xml" stylesheet="table.xsl"/>
>     </section>
>   </body>
> </document>

An alternative to Davids approach, which in many (but not all) use cases 
is easier, is to use XInclude.

Here you would provide a sitemap match to generate your required data 
(see links in Davids mail) and then use XInclude in your source XML 
similar to your "transform" element above.

You can see examples of how to do this in the Chart plugin inthe whitebaord:

For example "samples/graph1.xml" in the plugin docs includes:

<!-- combine is the way the datasets are placed together. I imagine 
"compare", "add" will be\possible among others
<graph combine="compare">
   <style>
     <!-- Use the specified "style" sheet.
	Format of the url is yet to be specified. -->
     <xi:include href="linechart1.xml"/>
   </style>

Ross

Re: XSL transformation as part of the page content?

Posted by Ross Gardler <rg...@apache.org>.
Victor Okunev wrote:
> I was able to perform the transformation and inject my custom HTML
> into the page using dedicated pipeline and without having to modify
> html2document.xsl. Thank you all for your help!
> 
> One remaining problem is that the html document I am injecting, refers
> to external CSS and JavaScript files. It is my understanding that XDoc
> doesn't support neither CSS nor JavaScript references. It seems my
> only choice is to modify skin's site2xhtml.xsl to hard code <link> and
> <script> tags respectively. Is there more elegant way?

Not in 0.7. Elegance will emerge with the dispatcher in a later version.

Ross


Re: XSL transformation as part of the page content?

Posted by Victor Okunev <ve...@gmail.com>.
I was able to perform the transformation and inject my custom HTML
into the page using dedicated pipeline and without having to modify
html2document.xsl. Thank you all for your help!

One remaining problem is that the html document I am injecting, refers
to external CSS and JavaScript files. It is my understanding that XDoc
doesn't support neither CSS nor JavaScript references. It seems my
only choice is to modify skin's site2xhtml.xsl to hard code <link> and
<script> tags respectively. Is there more elegant way?

-- Victor

On 2/13/06, Ross Gardler <rg...@apache.org> wrote:
> Victor Okunev wrote:
> > I guess this approach won't work if the transformation produces raw
> > html, which is not to be interpreted by Forrest. E.g. the result of my
> > transformation is not an HTML table but rather a <div>-based layout.
> > However, according to http://forrest.apache.org/dtd/document-v20.dtd,
> > these tags are not allowed in <body> element.
>
> There is an html2document.xsl that can be used to convert HTML to XDoc.
>
> However, you will find that most HTML tags will actually pass through
> the internal processing and work as-is as far as HTML page generation is
> concerned. Some strange effects may be seen in non-html output though,
> so we advise to convert to XDoc.
>
> > I think a situation like this one is very typical: someone has a
> > legacy html that does not necessarily validates against Forrest DTD,
> > but it needs to be embedded to the page.
>
> http://forrest.apache.org/docs_0_70/howto/howto-custom-html-source.html
>
> Ross
>

Re: XSL transformation as part of the page content?

Posted by Ross Gardler <rg...@apache.org>.
Victor Okunev wrote:
> I guess this approach won't work if the transformation produces raw
> html, which is not to be interpreted by Forrest. E.g. the result of my
> transformation is not an HTML table but rather a <div>-based layout.
> However, according to http://forrest.apache.org/dtd/document-v20.dtd,
> these tags are not allowed in <body> element.

There is an html2document.xsl that can be used to convert HTML to XDoc.

However, you will find that most HTML tags will actually pass through 
the internal processing and work as-is as far as HTML page generation is 
concerned. Some strange effects may be seen in non-html output though, 
so we advise to convert to XDoc.

> I think a situation like this one is very typical: someone has a
> legacy html that does not necessarily validates against Forrest DTD,
> but it needs to be embedded to the page.

http://forrest.apache.org/docs_0_70/howto/howto-custom-html-source.html

Ross

Re: XSL transformation as part of the page content?

Posted by Ross Gardler <rg...@apache.org>.
Thorsten Scherler wrote:
> El lun, 13-02-2006 a las 13:03 +0000, Ross Gardler escribió:

...

> 
>>The xi:include, or XSL processing of the source content is more 
>>efficient in this particular case. The dispatcher is more efficient if 
>>you want to put the same content into a large number of pages.
> 

...

> 
> ...and Victors problem is that he cannot use e.g. XInclude (it would be
> better to use CInclude anyway because it is cacheable -> but this as
> well a dev topic) because he want to add non valid markup (regarding
> xdocs dtd) into his doc.
> 
> If he goes the XInclude road he needs to trigger the include *after* the
> site2xhtml.xsl.

Not necessarily, see my earlier post on this subject.

Ross


Re: XSL transformation as part of the page content?

Posted by Thorsten Scherler <th...@wyona.com>.
El lun, 13-02-2006 a las 13:03 +0000, Ross Gardler escribió:
> Thorsten Scherler wrote:
> > El lun, 13-02-2006 a las 01:27 -0800, Victor Okunev escribió:
> > 
> >>I guess this approach won't work if the transformation produces raw
> >>html, which is not to be interpreted by Forrest. E.g. the result of my
> >>transformation is not an HTML table but rather a <div>-based layout.
> >>However, according to http://forrest.apache.org/dtd/document-v20.dtd,
> >>these tags are not allowed in <body> element.
> >>
> >>I think a situation like this one is very typical: someone has a
> >>legacy html that does not necessarily validates against Forrest DTD,
> >>but it needs to be embedded to the page.
> > 
> > 
> > ...and this is why we developing the dispatcher (new feature in 0.8-dev)
> > which solves this problem. ;-)
> 
> It is possible to solve this problem with the dispatcher, however, this 
> is integration of content into individual pages. The dispatcher is not 
> ideal for this since it would require a new structurer definition for 
> each page wanting to include something different.
> 
> The xi:include, or XSL processing of the source content is more 
> efficient in this particular case. The dispatcher is more efficient if 
> you want to put the same content into a large number of pages.

Well the current version of the dispatcher is really not ideal for it
*yet*, but I am ATM playing around with contract definitions *in* xdocs
(but xhtml2 based docs) and I can tell you that is *way* easier, but
this is a dev topic.

...and Victors problem is that he cannot use e.g. XInclude (it would be
better to use CInclude anyway because it is cacheable -> but this as
well a dev topic) because he want to add non valid markup (regarding
xdocs dtd) into his doc.

If he goes the XInclude road he needs to trigger the include *after* the
site2xhtml.xsl.

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


Re: XSL transformation as part of the page content?

Posted by Ross Gardler <rg...@apache.org>.
Thorsten Scherler wrote:
> El lun, 13-02-2006 a las 01:27 -0800, Victor Okunev escribió:
> 
>>I guess this approach won't work if the transformation produces raw
>>html, which is not to be interpreted by Forrest. E.g. the result of my
>>transformation is not an HTML table but rather a <div>-based layout.
>>However, according to http://forrest.apache.org/dtd/document-v20.dtd,
>>these tags are not allowed in <body> element.
>>
>>I think a situation like this one is very typical: someone has a
>>legacy html that does not necessarily validates against Forrest DTD,
>>but it needs to be embedded to the page.
> 
> 
> ...and this is why we developing the dispatcher (new feature in 0.8-dev)
> which solves this problem. ;-)

It is possible to solve this problem with the dispatcher, however, this 
is integration of content into individual pages. The dispatcher is not 
ideal for this since it would require a new structurer definition for 
each page wanting to include something different.

The xi:include, or XSL processing of the source content is more 
efficient in this particular case. The dispatcher is more efficient if 
you want to put the same content into a large number of pages.

Ross


Re: XSL transformation as part of the page content?

Posted by Thorsten Scherler <th...@apache.org>.
El lun, 13-02-2006 a las 01:27 -0800, Victor Okunev escribió:
> I guess this approach won't work if the transformation produces raw
> html, which is not to be interpreted by Forrest. E.g. the result of my
> transformation is not an HTML table but rather a <div>-based layout.
> However, according to http://forrest.apache.org/dtd/document-v20.dtd,
> these tags are not allowed in <body> element.
> 
> I think a situation like this one is very typical: someone has a
> legacy html that does not necessarily validates against Forrest DTD,
> but it needs to be embedded to the page.

...and this is why we developing the dispatcher (new feature in 0.8-dev)
which solves this problem. ;-)

salu2

> -- Victor
> 
> On 2/12/06, David Crossley <cr...@apache.org> wrote:
> > Victor Okunev wrote:
> > > Hi All,
> > >
> > > I have an XSLT style sheet that I use to generate an HTML table. Is it
> > > possible with Forrest v0.7 to perform the transformation as part of
> > > the site build and include the results under a document's section?
> > > Here is a pseudo code that kind of illustrates what I am after:
> > >
> > > index.xml
> > >
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <!--
> > >   Copyright....
> > > -->
> > > <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN"
> > > "http://forrest.apache.org/dtd/document-v20.dtd">
> > > <document>
> > >   <header>
> > >     <title>Page Title</title>
> > >   </header>
> > >   <body>
> > >     <section id="sectionid">
> > >       <title>Section Title</title>
> > >       <transform src="data.xml" stylesheet="table.xsl"/>
> > >     </section>
> > >   </body>
> > > </document>
> >
> > Yes, the Cocoon sitemap enables this and more.
> > This is a good situation to explain the powers
> > of teh Cocoon sitemap.
> >
> > Remove that <transform ... from your source xml
> > and use the sitemap language to specify the extra
> > transformer to inject the table into the xml stream.
> >
> > http://forrest.apache.org/docs/project-sitemap.html
> >
> > I attached some example files to a new issue.
> > http://issues.apache.org/jira/browse/FOR-814
> > You can download and use them. Later we will create
> > a document from this explanation.
> >
> > The source file xdocs/one-announce.xml is the main
> > announcement text. Like yours above, but without
> > the <transform> pseudo-stuff and with another section.
> >
> > The data table will be inserted in the top of the
> > first section.
> >
> > Here is the data file xdocs/one-data.xml
> > <data>
> >  <item>Foo</item>
> > </data>
> >
> > Here is the relevant section of the sitemap ...
> >
> >  <map:pipelines>
> >   <map:pipeline>
> >    <map:match pattern="**-announce.xml">
> >     <map:aggregate element="announce-and-data">
> >       <map:part src="{project:content.xdocs}{1}-announce.xml"/>
> >       <map:part src="{project:content.xdocs}{1}-data.xml"/>
> >      </map:aggregate>
> >     <map:transform src="{project:resources.stylesheets}/add-table.xsl" />
> >     <map:serialize type="xml-document"/>
> >    </map:match>
> >   </map:pipeline>
> >  </map:pipelines>
> >
> > Browser request is localhost:8888/one-announce.html
> >
> > So that generates an aggregated xml stream like this ...
> > <announce-and-data>
> >  <document>
> >    ... the normal source xdoc, e.g. one-announce.xml
> >  </document>
> >  <data>
> >   <item>Foo</item>
> >  </data>
> > </announce-and-data>
> >
> > The add-table transformer then strips off the outer wrapper,
> > copies over the <document> content, deals with the first
> > <section> element and inserts the table by processing
> > the <data> element. It serialises as the "xml-document"
> > which is Forrest's internal format. Forrest takes over
> > and does the rest of the transforming and rendering.
> >
> > That is the general idea. There are probably other
> > ways to do it too.
> >
> > The new dispatcher will be even more versatile.
> >
> > -David
> >
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)


Re: XSL transformation as part of the page content?

Posted by Victor Okunev <ve...@gmail.com>.
I guess this approach won't work if the transformation produces raw
html, which is not to be interpreted by Forrest. E.g. the result of my
transformation is not an HTML table but rather a <div>-based layout.
However, according to http://forrest.apache.org/dtd/document-v20.dtd,
these tags are not allowed in <body> element.

I think a situation like this one is very typical: someone has a
legacy html that does not necessarily validates against Forrest DTD,
but it needs to be embedded to the page.

-- Victor

On 2/12/06, David Crossley <cr...@apache.org> wrote:
> Victor Okunev wrote:
> > Hi All,
> >
> > I have an XSLT style sheet that I use to generate an HTML table. Is it
> > possible with Forrest v0.7 to perform the transformation as part of
> > the site build and include the results under a document's section?
> > Here is a pseudo code that kind of illustrates what I am after:
> >
> > index.xml
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!--
> >   Copyright....
> > -->
> > <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN"
> > "http://forrest.apache.org/dtd/document-v20.dtd">
> > <document>
> >   <header>
> >     <title>Page Title</title>
> >   </header>
> >   <body>
> >     <section id="sectionid">
> >       <title>Section Title</title>
> >       <transform src="data.xml" stylesheet="table.xsl"/>
> >     </section>
> >   </body>
> > </document>
>
> Yes, the Cocoon sitemap enables this and more.
> This is a good situation to explain the powers
> of teh Cocoon sitemap.
>
> Remove that <transform ... from your source xml
> and use the sitemap language to specify the extra
> transformer to inject the table into the xml stream.
>
> http://forrest.apache.org/docs/project-sitemap.html
>
> I attached some example files to a new issue.
> http://issues.apache.org/jira/browse/FOR-814
> You can download and use them. Later we will create
> a document from this explanation.
>
> The source file xdocs/one-announce.xml is the main
> announcement text. Like yours above, but without
> the <transform> pseudo-stuff and with another section.
>
> The data table will be inserted in the top of the
> first section.
>
> Here is the data file xdocs/one-data.xml
> <data>
>  <item>Foo</item>
> </data>
>
> Here is the relevant section of the sitemap ...
>
>  <map:pipelines>
>   <map:pipeline>
>    <map:match pattern="**-announce.xml">
>     <map:aggregate element="announce-and-data">
>       <map:part src="{project:content.xdocs}{1}-announce.xml"/>
>       <map:part src="{project:content.xdocs}{1}-data.xml"/>
>      </map:aggregate>
>     <map:transform src="{project:resources.stylesheets}/add-table.xsl" />
>     <map:serialize type="xml-document"/>
>    </map:match>
>   </map:pipeline>
>  </map:pipelines>
>
> Browser request is localhost:8888/one-announce.html
>
> So that generates an aggregated xml stream like this ...
> <announce-and-data>
>  <document>
>    ... the normal source xdoc, e.g. one-announce.xml
>  </document>
>  <data>
>   <item>Foo</item>
>  </data>
> </announce-and-data>
>
> The add-table transformer then strips off the outer wrapper,
> copies over the <document> content, deals with the first
> <section> element and inserts the table by processing
> the <data> element. It serialises as the "xml-document"
> which is Forrest's internal format. Forrest takes over
> and does the rest of the transforming and rendering.
>
> That is the general idea. There are probably other
> ways to do it too.
>
> The new dispatcher will be even more versatile.
>
> -David
>

Re: XSL transformation as part of the page content?

Posted by David Crossley <cr...@apache.org>.
Victor Okunev wrote:
> Hi All,
> 
> I have an XSLT style sheet that I use to generate an HTML table. Is it
> possible with Forrest v0.7 to perform the transformation as part of
> the site build and include the results under a document's section?
> Here is a pseudo code that kind of illustrates what I am after:
> 
> index.xml
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!--
>   Copyright....
> -->
> <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN"
> "http://forrest.apache.org/dtd/document-v20.dtd">
> <document>
>   <header>
>     <title>Page Title</title>
>   </header>
>   <body>
>     <section id="sectionid">
>       <title>Section Title</title>
>       <transform src="data.xml" stylesheet="table.xsl"/>
>     </section>
>   </body>
> </document>

Yes, the Cocoon sitemap enables this and more.
This is a good situation to explain the powers
of teh Cocoon sitemap.

Remove that <transform ... from your source xml
and use the sitemap language to specify the extra
transformer to inject the table into the xml stream.

http://forrest.apache.org/docs/project-sitemap.html

I attached some example files to a new issue.
http://issues.apache.org/jira/browse/FOR-814
You can download and use them. Later we will create
a document from this explanation.

The source file xdocs/one-announce.xml is the main
announcement text. Like yours above, but without
the <transform> pseudo-stuff and with another section.

The data table will be inserted in the top of the
first section.

Here is the data file xdocs/one-data.xml
<data>
 <item>Foo</item>
</data>

Here is the relevant section of the sitemap ...

 <map:pipelines>
  <map:pipeline>
   <map:match pattern="**-announce.xml">
    <map:aggregate element="announce-and-data">
      <map:part src="{project:content.xdocs}{1}-announce.xml"/>
      <map:part src="{project:content.xdocs}{1}-data.xml"/>
     </map:aggregate>
    <map:transform src="{project:resources.stylesheets}/add-table.xsl" />
    <map:serialize type="xml-document"/>
   </map:match>
  </map:pipeline>
 </map:pipelines>

Browser request is localhost:8888/one-announce.html

So that generates an aggregated xml stream like this ...
<announce-and-data>
 <document>
   ... the normal source xdoc, e.g. one-announce.xml
 </document>
 <data>
  <item>Foo</item>
 </data>
</announce-and-data>

The add-table transformer then strips off the outer wrapper,
copies over the <document> content, deals with the first
<section> element and inserts the table by processing
the <data> element. It serialises as the "xml-document"
which is Forrest's internal format. Forrest takes over
and does the rest of the transforming and rendering.

That is the general idea. There are probably other
ways to do it too.

The new dispatcher will be even more versatile.

-David