You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Karl Oie <ka...@gan.no> on 2001/08/09 17:46:17 UTC

newbie question: (XML->XSLT) cached -> session logic -> browser??

Hi, im pretty new to cocoon2 so i need some advice about the best aproach
for my problem;

I got a quite large XML file which i use a XSL stylesheet to extract only
parts of, but the XML file might change so i set this up as the generator.

<map:match pattern="toc.html">
	<map:generate src="largefile.xml"/>
	<map:transform src="toc.xsl"/>

	... perform logic on the result based on sessions ...

	<map:serialize type="html"/>
</map:match>

Then based on the the user's session state i want to perform logic on the
extract, to hide and show elements (this is a session based toc).

What can i use to do this, a XSP, JSP, write a new
generator/transformer/serializer ?

Is it possible to place session handling in a custom serializer? is this a
job for a transformer, and will i then have to implement it myself and is it
then possible to add session handling?

Should i create a custom generator, if so how to implement caching and
session handling?

I'm quite good at java, but i'm new to cocoon and need some pointers in the
right direction.

in advance thanks!

mvh Karl


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Replacing \n with
-> cocoon pb ?

Posted by Sébastien Lefebvre <sl...@i2m.fr>.
Hi folks !

I have text in a database with \n characters in it.
I want to produce HTML and keep LF in my presentation.
So I have to convert \n to <BR>

I can't replace with < and > characters because they can be confusing 
for the parser , am I right ?
In order to see if my template is ok, I tried it but I have a 
StackOverFlowError ! (replacing \n with BR )
Any help is appreciated

Thanks

Sébastien






Here is what I did :

<xsl:template name="remplaceCaracDansChaine">
    <xsl:param name="chaineEntrante"/><!--Input String-->
    <xsl:param name="caracEntrant"/>    <!--what I want to be replaced-->
    <xsl:param name="caracSortant"/><!--the new piece of string-->
    <xsl:choose>
        <xsl:when test="contains($chaineEntrante,caracEntrant)">
            <xsl:value-of 
select="concat(substring-before($chaineEntrante,$caracEntrant),$caracSortant)"/>
    <xsl:call-template name="remplaceCaracDansChaine">
    <xsl:with-param name="chaineEntrante" 
select="substring-after($chaineEntrante,$caracEntrant)"/>
    <xsl:with-param name="caracEntrant" select="$caracEntrant"/>
    <xsl:with-param name="caracSortant" select="$caracSortant"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="$chaineEntrante"/>
    </xsl:otherwise>
    </xsl:choose>
</xsl:template>

Then, I call it like that :
<xsl:variable name="monTexte"><xsl:value-of 
select="/page/rowfiche/texte"/></xsl:variable> <!--value coming from my 
XML-->
<xsl:variable name="texteBR"><!--the destination variable with modified 
text-->
    <xsl:call-template name="remplaceCaracDansChaine">
        <xsl:with-param name="chaineEntrante" select="string($monTexte)"/>
        <xsl:with-param name="caracEntrant" select="n"/>
        <xsl:with-param name="caracSortant" select="BR"/><!--I can't use 
<BR> because of < and > characters-->
    </xsl:call-template>
</xsl:variable>

<xsl:value-of select="$texteBR"/><!--print the transformed string-->


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: newbie question: (XML->XSLT) cached -> session logic -> browser??

Posted by fo...@neonics.com.
Just create an XSP page,
with a template matching the root element of your xml page.
Then do some if-then-else based on your session.
In each 'if' body you do something like this:

  if (some_session_based_expression)
  {
	<xsl:call-template name="henk"/>
  }
  else if (....)
....

The template 'henk' is inserted in the place of the call.
If it just consists of content, it looks like this:

<xsl:template name="henk">
  <xsp:content>
    <!-- xsl code that applies templates to the parts you want -->
  </xsp:content>
</xsl:template>

This way you get 1 producer/generator, which can produce all the 
different pages you want (that is, sections of your XML document)
based on some viariables in the session.


I use this technique to validate users:

The XML document:

	<nsp:auth group="users">
          <success>
            <!-- data you want to show when the user is logged
                 in and belongs to that group -->
          </success>
          <fail>
            <nsp:login-form/> <!-- or some other xml code.. -->
          </fail>
        </nsp:auth>

The xsp page:

<xsl:template match="nsp:auth">
  <xsp:logic>
    if (userInGroup("<xsl:value-of select="@group"/>"))
    {
	<xsp:content>
	<xsl:apply-templates select="success"/>
        </xsp:content>
    }
    else
    {
	<xsp:content>
        <xsl:apply-templates select="fail"/>
        </xsp:content>
    }
  </xsp:logic>
 
</xsl:template>


The UserInGroup checks the session for a user object, standard code..

Hope this helps,

	Kenney Westerhof

On Thu, 9 Aug 2001, Karl Oie wrote:

> Hi, im pretty new to cocoon2 so i need some advice about the best aproach
> for my problem;
> 
> I got a quite large XML file which i use a XSL stylesheet to extract only
> parts of, but the XML file might change so i set this up as the generator.
> 
> <map:match pattern="toc.html">
> 	<map:generate src="largefile.xml"/>
> 	<map:transform src="toc.xsl"/>
> 
> 	... perform logic on the result based on sessions ...
> 
> 	<map:serialize type="html"/>
> </map:match>
> 
> Then based on the the user's session state i want to perform logic on the
> extract, to hide and show elements (this is a session based toc).
> 
> What can i use to do this, a XSP, JSP, write a new
> generator/transformer/serializer ?
> 
> Is it possible to place session handling in a custom serializer? is this a
> job for a transformer, and will i then have to implement it myself and is it
> then possible to add session handling?
> 
> Should i create a custom generator, if so how to implement caching and
> session handling?
> 
> I'm quite good at java, but i'm new to cocoon and need some pointers in the
> right direction.
> 
> in advance thanks!
> 
> mvh Karl
> 
> 
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> 
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
> 


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>