You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Alexander <al...@gmx.at> on 2003/05/14 22:02:45 UTC

"path" problem; difficult to describe in one subject line ;-)

I want to use Cocoon to integrate different sources, containing XML/XSL, 
database and also HTML: the problem:

(1) I have html documents in a file hierarchy and I do the following in 
the sitemap:

<map:match pattern="**.html">
                <map:generate src="html/{1}.html" type="html"/>
                <map:transform src="style/default.xsl" type="xslt"/>
                <map:serialize type="html" />
</map:match>


(2) The default.xsl does mainly the following: extract the content of 
the <body> tag from the html documents and put them into a "design" 
XHTML table, that is containing a header and a navigation bar on the 
left. works perfectly good.


(3) the problem is the path hierarchy: html documents could be (as an 
example):

/html/index.html
/html/hi.html
/html/images/start.html


(4) PROBLEM:

now I have a problem with the navigational links in the default.xsl, 
because when they point relative to "index.html", this works in the html 
directory, hence for "hi.html", but obviously not for "start.html", as 
the link in the generated page would point to "/html/images/index.html" 
instead of "/html/index.html"

This concept is very similar to the templates functionality in 
Dreamweaver, which rewrites the URLs in the second case to ../index.html.

(5) Solution?

unfortunatly, this strategy is so fine, but I found no really clean 
solution for this problem, except to write absolute URLs as links in the 
naviation bar, hence something like "http://www.mysite.org/index.html", 
but this is no real good solution, as it poses some other new problems 
and is limited in portability, it works, though.

Has some Cocoon guru a solution for this? I believe if this would word, 
this is an excellent usage pattern for Cocoon to integrate available 
html pages as well a new writte HTML, as it is far easier for content 
makers to write "simple" pages using e.g. Dreamweaver instead of some 
XML editor, however.


thank you in advance!!


Alex


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


Re: "path" problem; difficult to describe in one subject line ;-)

Posted by Andreas Hartmann <an...@apache.org>.
Alexander Schatten wrote:

> !!thank you very much for this great solution!!

No problem :)

> just one very brief and unimportant coomment:
> 
> Andreas Hartmann wrote:
> 
>>   </map:parameter name="url" value="{1}.html">
> 
> this {1}.html is not necessary, {1} should be enough.

Sure, in this case it is.
It becomes important when you match the URI against others,
e.g. to highlight the current menu position, when there are
URLs like "index.html" and "index.php".

> maybe one could add this to the cocoon docs/examples, because I believe, 
> that this is a great solution that could help many others,

I can put a small article on cocooncenter when I find some time.

Andreas



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


Re: "path" problem; difficult to describe in one subject line ;-)

Posted by Alexander Schatten <al...@gmx.at>.
!!thank you very much for this great solution!!

I had already some similar idea, but I had problems I could not solve; 
e.g. I did not come to the idea to call the recursive template from the 
variable... and finally thought into the wrong direction and stuck...

just one very brief and unimportant coomment:

Andreas Hartmann wrote:

>   </map:parameter name="url" value="{1}.html">


this {1}.html is not necessary, {1} should be enough.


maybe one could add this to the cocoon docs/examples, because I believe, 
that this is a great solution that could help many others,


thanks


alex


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


Re: "path" problem; difficult to describe in one subject line ;-)

Posted by Andreas Hartmann <an...@apache.org>.
Alexander wrote:

[...]

> Has some Cocoon guru a solution for this? I believe if this would word, 
> this is an excellent usage pattern for Cocoon to integrate available 
> html pages as well a new writte HTML, as it is far easier for content 
> makers to write "simple" pages using e.g. Dreamweaver instead of some 
> XML editor, however.


You can pass the URL to your stylesheet:

<map:match pattern="**.html">
   <map:generate src="html/{1}.html" type="html"/>
   <map:transform src="style/default.xsl" type="xslt">
   </map:parameter name="url" value="{1}.html">
   <map:serialize type="html" />
</map:match>

Then you can compute the relative path to the root
using a recursive template:

<xsl:param name="url"/>

<xsl:variable name="path-to-context"><xsl:call-template
    name="create-path-to-context"/></xsl:variable>

<xsl:template name="create-path-to-context">
   <xsl:param name="local-url" select="$url"/>
   <xsl:if test="contains($local-url, '/')">
     <xsl:text/>../<xsl:call-template name="create-path-to-context">
       <xsl:with-param name="local-url"
	select="substring-after($local-url, '/')"/>
     </xsl:call-template>
   </xsl:if>
</xsl:template>

Now you can use $path-to-context to create some relative URLs:

<a href="{$path-to-context}/images/myimage.index.html">

Maybe there is a better solution, but this is what I use for
cocooncenter.

HTH,
Andreas



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