cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robby Pelssers" <robby.pelss...@ciber.nl>
Subject FW: question about how to reference a css file from within xslt (cocoon 2.2)
Date Thu, 26 Jun 2008 11:53:47 GMT
Well, i solved my styling issue so just in case anybody might have the
same problem:

 

 

Attached screenshot of my folder structure and some snippets of the
files used.

 

 

Here are some snippets:

 

com.ciber.actions.ExportAction:

---------------------------------------------

package com.ciber.actions;

 

import java.util.HashMap;

import java.util.Map;

 

import org.apache.avalon.framework.parameters.Parameters;

import org.apache.cocoon.acting.AbstractAction;

import org.apache.cocoon.environment.ObjectModelHelper;

import org.apache.cocoon.environment.Redirector;

import org.apache.cocoon.environment.Request;

import org.apache.cocoon.environment.SourceResolver;

 

 

/**

 * 

 * @author robby.pelssers

 * This action is responsible for determining the export type (so we
know which serializer to use)

 * E.g.:  

 *      - pdf

 *      - xml

 *      - xhtml

 *      - ...

 */

public class ExportAction extends AbstractAction {

 

    @Override

    public Map act(Redirector redirector, SourceResolver resolver, Map
objectModel, String source,

            Parameters params) throws Exception {

        

        Map sitemapParams = new HashMap();

        Request request = ObjectModelHelper.getRequest(objectModel);

        String requestURI = request.getRequestURI();

        String exportType =
requestURI.substring(requestURI.lastIndexOf(".") + 1);

        sitemapParams.put("export-type", exportType);

        

        return sitemapParams;

    }

 

}

 

 

Sitemap.xml:

------------------------

 

  <map:components>

    <map:actions>

      <map:action name="export" src="com.ciber.actions.ExportAction"/>

    </map:actions>  

  </map:components>  

  

  <map:resources>

    <map:resource name="publish">

      <map:act type="export">

        <map:select type="parameter">

          <map:parameter name="parameter-selector-test"
value="{export-type}"/>

              <map:when test="xml">

                 <map:serialize type="xml"/>                        

              </map:when>

              <map:when test="xhtml">

                <map:transform
src="resource/internal/xslt/xml2xhtml.xslt"/>

                   <map:serialize type="xhtml"/>


              </map:when>

              <map:otherwise>

                   <map:serialize type="xml"/>


              </map:otherwise>

        </map:select>

      </map:act> 

    </map:resource>

  </map:resources>

 

  <map:pipelines>

    <map:pipeline id="static-content">

      <map:match pattern="static/page/page-*.*">

         <map:generate src="myDemo/static/page/page-{1}.xml"/>

         <map:call resource="publish"/>

      </map:match>  

    </map:pipeline>

            .....

  </map:pipelines>        

 

Xml2xhtml.xsl:

------------------------

 

  <xsl:template match="/">

    <html>

      <head>

        <title><xsl:value-of select="page/title/text()"/></title>

        <link rel="stylesheet"
href="../../resource/external/css/myDemo.css" type="text/css"/>

      </head>

      <body>

        <xsl:apply-templates/>

      </body>

    </html>

  </xsl:template>

 

   .... 

________________________________

From: Robby Pelssers 
Sent: dinsdag 24 juni 2008 14:44
To: users@cocoon.apache.org
Subject: question about how to reference a css file from within xslt
(cocoon 2.2)

 

Hi all,

 

I can't seem to retrieve the css file (myDemo.css).  Anybody who could
give me a hint about what's wrong with my current configuration?

 

When I take a look at the generated html page, the source looks OK to
me.

 

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>Cocoon Demo by Ciber</title>
    <link type="text/css" href="resource/external/css/myDemo.css"
rel="stylesheet" />
  </head>
  <body>
    ....
 
But I do not see any css styling applied and when I try to take a look
at the css file (via firefox webdeveloper plugin) that should ship with
this page, it looks as if cocoon serves the transformed page-home.xml as
myDemo.css
 

 

 

My folder structure looks like:

 

* COB-INF

            * myDemo

                        * page

                                    * page-home.xml           

                        * xslt    

                                    * xml2xhtml.xslt

            * resource

                        *external

                                   * css

                                               * myDemo.css

 

 

Xml2html.xslt snippet:

 

  <xsl:template match="/">

    <html>

      <head>

        <title><xsl:value-of select="page/title/text()"/></title>

        <link rel="stylesheet" href="resource/external/css/myDemo.css"
type="text/css"/>

      </head>

      <body>

        <xsl:apply-templates/>

      </body>

    </html>

  </xsl:template>

 

 

 

Sitemap snippet:

-------------------------

 

<map:pipelines>

  <map:pipeline id="genericPages">

    <map:match pattern="page-home.xml"/>

    <map:generate src="myDemo/page/page-home.xml"/>

            <map:transform src="myDemo/xslt/xml2xhtml.xslt"/>

            <map:serialize type="xhtml"/>

  </map:pipeline>

   ....    

  <map:pipeline id="external-resource">

            <map:match pattern="resource/external/css/myDemo.css">

      <map:read src="resource/external/css/myDemo.css"/>

    </map:match>                      

    <map:match pattern="resource/external/**">

      <map:read src="resource/external/{1}"/>

    </map:match>

  </map:pipeline>  

   ...

</map:pipelines>

            

 

Cheers,

 

Robby Pelssers


Mime
View raw message