You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by leon tian <ti...@yahoo.co.uk> on 2004/05/17 15:53:46 UTC

apply css?

hi,
 
is there any way to apply the css of the original web pages from the internet? after i transform web pages from the internet, most of the styles are lost because they are linked to a css file on the web site's server. should i try to download and apply them on my resulting pages and how?
 
thanks in advance;)
 
 
Leon

		
---------------------------------
  Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now

Re: apply css?

Posted by leon tian <ti...@yahoo.co.uk>.
I'll try myself. Thanks for all the helps!


Joerg Heinicke <jo...@gmx.de> wrote:
On 18.05.2004 02:19, leon tian wrote:

> Hi, there are only descriptions. Where can I see the sample of linkrewriter? Thanks.

It's a block, so edit your local.blocks.properties to include it. At the 
end the samples should be accessible at 
http://localhost:8888/samples/blocks/linkrewriter/.

The page also recommends to read the Javadoc, probably it's the 
only/best docu available: 
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/transformation/LinkRewriterTransformer.html

I can't you help anymore on its usage.

Joerg

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

		
---------------------------------
  Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now

Re: apply css?

Posted by Joerg Heinicke <jo...@gmx.de>.
On 18.05.2004 02:19, leon tian wrote:

> Hi, there are only descriptions. Where can I see the sample of linkrewriter? Thanks.

It's a block, so edit your local.blocks.properties to include it. At the 
end the samples should be accessible at 
http://localhost:8888/samples/blocks/linkrewriter/.

The page also recommends to read the Javadoc, probably it's the 
only/best docu available: 
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/transformation/LinkRewriterTransformer.html

I can't you help anymore on its usage.

Joerg

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


Re: apply css?

Posted by leon tian <ti...@yahoo.co.uk>.
Hi, there are only descriptions. Where can I see the sample of linkrewriter? Thanks.

Joerg Heinicke <jo...@gmx.de> wrote:On 18.05.2004 01:39, leon tian wrote:

> Hi, thanks for such detailed reply! I got it with 1 more question.
> Some remote pages reference their resources to the remote server like
> href="/css.css", the others using full url like
> href="http://www.remote.com/css.css". I'm thinking using your method
> 1 plus 'xsl:choose' to test the first four letters of 'href'
> (==http?) and link it to the correct url. But I don't know how to
> test the first four letters. Could you tell me how although it is
> more likely a xsl question.

xsl: starts-with(whatToTest, 'http')

There is also a linkrewriter block in Cocoon that might do this job in a 
more sophisticated way:
http://wiki.cocoondev.org/Wiki.jsp?page=BlockDescriptions. Maybe you get 
it to work.

Joerg

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


		
---------------------------------
  Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now

Re: apply css?

Posted by Joerg Heinicke <jo...@gmx.de>.
Maybe you already solved it in the meantime ...

On 18.05.2004 03:33, leon tian wrote:

> Hi, i tried to using xsl:choose to link the img but the first 'when' doesn't work. Could you spot the error for me? Thanks.

No, it looks ok. What does "doesn't work" mean? It's never evaluated to 
true?

Joerg

> <xsl:template match="img/@src">
> <xsl:variable name="link" select="." />
>  <xsl:attribute name="src">
>   <xsl:choose>
>    <xsl:when test="starts-with($link ,'http')">
>     <xsl:value-of select="."/>
>    </xsl:when>
>    <xsl:otherwise>
>     <xsl:value-of select="concat($remoteserver, .)"/>
>    </xsl:otherwise>
>   </xsl:choose>
>    </xsl:attribute>
> </xsl:template>
> 
> Joerg Heinicke <jo...@gmx.de> wrote:
> On 18.05.2004 01:39, leon tian wrote:
> 
> 
>>Hi, thanks for such detailed reply! I got it with 1 more question.
>>Some remote pages reference their resources to the remote server like
>>href="/css.css", the others using full url like
>>href="http://www.remote.com/css.css". I'm thinking using your method
>>1 plus 'xsl:choose' to test the first four letters of 'href'
>>(==http?) and link it to the correct url. But I don't know how to
>>test the first four letters. Could you tell me how although it is
>>more likely a xsl question.
> 
> 
> xsl: starts-with(whatToTest, 'http')
> 
> There is also a linkrewriter block in Cocoon that might do this job in a 
> more sophisticated way:
> http://wiki.cocoondev.org/Wiki.jsp?page=BlockDescriptions. Maybe you get 
> it to work.
> 
> Joerg

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


Re: apply css?

Posted by leon tian <ti...@yahoo.co.uk>.
Hi, i tried to using xsl:choose to link the img but the first 'when' doesn't work. Could you spot the error for me? Thanks.
 
<xsl:template match="img/@src">
<xsl:variable name="link" select="." />
 <xsl:attribute name="src">
  <xsl:choose>
   <xsl:when test="starts-with($link ,'http')">
    <xsl:value-of select="."/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="concat($remoteserver, .)"/>
   </xsl:otherwise>
  </xsl:choose>
   </xsl:attribute>
</xsl:template>

Joerg Heinicke <jo...@gmx.de> wrote:
On 18.05.2004 01:39, leon tian wrote:

> Hi, thanks for such detailed reply! I got it with 1 more question.
> Some remote pages reference their resources to the remote server like
> href="/css.css", the others using full url like
> href="http://www.remote.com/css.css". I'm thinking using your method
> 1 plus 'xsl:choose' to test the first four letters of 'href'
> (==http?) and link it to the correct url. But I don't know how to
> test the first four letters. Could you tell me how although it is
> more likely a xsl question.

xsl: starts-with(whatToTest, 'http')

There is also a linkrewriter block in Cocoon that might do this job in a 
more sophisticated way:
http://wiki.cocoondev.org/Wiki.jsp?page=BlockDescriptions. Maybe you get 
it to work.

Joerg

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

		
---------------------------------
  Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now

Re: apply css?

Posted by Joerg Heinicke <jo...@gmx.de>.
On 18.05.2004 01:39, leon tian wrote:

> Hi, thanks for such detailed reply! I got it with 1 more question.
> Some remote pages reference their resources to the remote server like
> href="/css.css", the others using full url like
> href="http://www.remote.com/css.css". I'm thinking using your method
> 1 plus 'xsl:choose' to test the first four letters of 'href'
> (==http?) and link it to the correct url. But I don't know how to
> test the first four letters. Could you tell me how although it is
> more likely a xsl question.

xsl: starts-with(whatToTest, 'http')

There is also a linkrewriter block in Cocoon that might do this job in a 
more sophisticated way:
http://wiki.cocoondev.org/Wiki.jsp?page=BlockDescriptions. Maybe you get 
it to work.

Joerg

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


Re: apply css?

Posted by leon tian <ti...@yahoo.co.uk>.
Hi, thanks for such detailed reply! I got it with 1 more question. Some remote pages reference their resources to the remote server like href="/css.css", the others using full url like href="http://www.remote.com/css.css". I'm thinking using your method 1 plus 'xsl:choose' to test the first four letters of 'href' (==http?) and link it to the correct url. But I don't know how to test the first four letters. Could you tell me how although it is more likely a xsl question. 
 
Regards


Joerg Heinicke <jo...@gmx.de> wrote:
On 17.05.2004 23:45, leon tian wrote:

> Hi, thanks for the reply. But I wanna transform web pages from the
> internet dynamically which means different css should be applied
> based on different web pages. How can I get the url of each css
> automatically (like a web browser)?

You mean my example was to simple as it was only one hardcoded remote 
resource?

With a pipeline of your current sitemap it would be easier for me to 
give an example, but maybe you see what I try to suggest:

1. Absolutize the links to the external resources:

Somewhere you have to determine where to get a web page from, don't you? 
This part you can pass into a stylesheet as parameter that absolutizes 
the links to CSS, JS and images.









In the stylesheet you match on link/@href, style/@src, img/@src etc. and 
change all relative links:







The resources would be fetched from the remote server without any Cocoon 
inbetween.

2. forward the request to the remote server










In the same way you determine the remote URL for the web page you can do 
it for the CSS. And even if this is not possible, you can add a 
transformer into the remote.html pipeline that adds a hint on the remote 
server into all resource links (same as in approach 1). In the CSS 
pipeline you get them from the URL













The difference is then only that those resources are delivered through 
Cocoon, not grabbed from the remote server directly.

Hope you get the ideas.

Joerg


> Joerg Heinicke wrote: On 17.05.2004 15:53,
> 
>> hi,
>> 
>> is there any way to apply the css of the original web pages from
>> the internet? after i transform web pages from the internet, most
>> of the styles are lost because they are linked to a css file on the
>> web site's server. should i try to download and apply them on my 
>> resulting pages and how?
> 
> 
> It should be easy to forward the request to the CSS to the original 
> server in the same way as you get the HTML source.


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

		
---------------------------------
  Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now

Re: apply css?

Posted by Joerg Heinicke <jo...@gmx.de>.
On 17.05.2004 23:45, leon tian wrote:

> Hi, thanks for the reply. But I wanna transform web pages from the
> internet dynamically which means different css should be applied
> based on different web pages. How can I get the url of each css
> automatically (like a web browser)?

You mean my example was to simple as it was only one hardcoded remote 
resource?

With a pipeline of your current sitemap it would be easier for me to 
give an example, but maybe you see what I try to suggest:

1. Absolutize the links to the external resources:

Somewhere you have to determine where to get a web page from, don't you? 
This part you can pass into a stylesheet as parameter that absolutizes 
the links to CSS, JS and images.

<map:match pattern="remote.html">
   <map:generate type="html" src="{remoteserver}/index.html"/>
   <map:transform src="absolutize.xsl">
     <map:parameter name="remoteserver" value="{remoteserver}"/>
   </map:transform>
   <map:serialize/>
</map:match>

In the stylesheet you match on link/@href, style/@src, img/@src etc. and 
change all relative links:

<xsl:template match="link/@href">
   <xsl:attribute name="href">
     <xsl:value-of select="concat($remoteserver, '/', .)"/>
   </xsl:attribute>
</xsl:template>

The resources would be fetched from the remote server without any Cocoon 
inbetween.

2. forward the request to the remote server

<map:match pattern="remote.html">
   <map:generate type="html" src="{remoteserver}/index.html"/>
   <map:serialize/>
</map:match>

<map:match pattern="**.css">
   <map:read src="{remoteserver}/{0}"/>
</map:match>

In the same way you determine the remote URL for the web page you can do 
it for the CSS. And even if this is not possible, you can add a 
transformer into the remote.html pipeline that adds a hint on the remote 
server into all resource links (same as in approach 1). In the CSS 
pipeline you get them from the URL

<map:match pattern="remote.html">
   <map:generate type="html" src="{remoteserver}/index.html"/>
   <map:transform src="addRemoteServerHint">
     <map:parameter name="remoteserver" value="{remoteserver}"/>
   </map:transform>
   <map:serialize/>
</map:match>

<map:match pattern="*/**.css">
   <map:read src="http://{1}/{2}.css"/>
</map:match>

The difference is then only that those resources are delivered through 
Cocoon, not grabbed from the remote server directly.

Hope you get the ideas.

Joerg


> Joerg Heinicke wrote: On 17.05.2004 15:53,
> 
>> hi,
>> 
>> is there any way to apply the css of the original web pages from
>> the internet? after i transform web pages from the internet, most
>> of the styles are lost because they are linked to a css file on the
>> web site's server. should i try to download and apply them on my 
>> resulting pages and how?
> 
> 
> It should be easy to forward the request to the CSS to the original 
> server in the same way as you get the HTML source.


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


Re: apply css?

Posted by leon tian <ti...@yahoo.co.uk>.
Hi, thanks for the reply. But I wanna transform web pages from the internet dynamically which means different css should be applied based on different web pages. How can I get the url of each css automatically (like a web browser)?


Joerg Heinicke <jo...@gmx.de> wrote:
On 17.05.2004 15:53, leon tian wrote:

> hi,
> 
> is there any way to apply the css of the original web pages from the
> internet? after i transform web pages from the internet, most of the
> styles are lost because they are linked to a css file on the web
> site's server. should i try to download and apply them on my
> resulting pages and how?

It should be easy to forward the request to the CSS to the original 
server in the same way as you get the HTML source.

Example:









where original index.html from www.remote.com has a reference to 
css/main.css.

Joerg

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

		
---------------------------------
  Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now

Re: apply css?

Posted by Joerg Heinicke <jo...@gmx.de>.
On 17.05.2004 15:53, leon tian wrote:

> hi,
> 
> is there any way to apply the css of the original web pages from the
> internet? after i transform web pages from the internet, most of the
> styles are lost because they are linked to a css file on the web
> site's server. should i try to download and apply them on my
> resulting pages and how?

It should be easy to forward the request to the CSS to the original 
server in the same way as you get the HTML source.

Example:

<map:match pattern="remote.html">
   <map:read src="http://www.remote.com/index.html"/>
</map:match>

<map:match pattern="css/main.css">
   <map:read src="http://www.remote.com/css/main.css"/>
</map:match>

where original index.html from www.remote.com has a reference to 
css/main.css.

Joerg

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