You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Ugo Cei <u....@cbim.it> on 2002/09/18 09:51:07 UTC

Re: AW: Integrating XML formatted information directly with navigatio nal structures

Majcen, Kurt wrote:
> Some questions remain (at least for me):
> - Should the generator produce 1 XML (including the various 'XML rows' from
> the database and maybe a tag for the PREV and the NEXT) or should it produce
> a series of XMLs (1 for each record from the DB)?

A generator has to produce a single well-formed XML document, with a 
single root element. You could write a single generator that takes as an 
optional parameter a record number. If the parameter is present, output 
that record, if not, output the summary list.

> - Can I somehow make the query (results) persistent for the PREV/NEXT
> mechanisms? Does this have to be done in the generator?

You could always output the whole database from your generator, have it 
implement the Cacheable interface, with suitable generateKey() and 
generateValidity() methods, and use the Paginator Transformer [1] to 
navigate through records.

Another method I used is to use a CachedRowSet (included in JDBC 2.0, 
but available separately [2]). I've used it to in an application where 
it would have been impractical to cache the full results of a query, so 
I cached just the keys and fetched a single record at a time when 
requested, given the key.

To explain better: I have a generator that acccepts two optional 
parameters:

The first one, "q", is a query string and is used to initialize a new 
CachedRowSet from a querly like the following:

	select key from tablename where description like '%q%'

the rowset obtained from this query is associated to a user session, 
then the current row in the rowset is set to the first one, it's "key" 
column is fetched ad used to execute a query like the following:

	select * from tablename where key = 'key'

then the table columns are output in XML.

The second one, "cmd", can have values "first", "last", "next" and 
"prev". Its value is used to do a first(), last(), next() or prev() 
operation on the rowset (taken from the current session). Then I use the 
key value to perform again the second query above.

	Hope this helps,

		Ugo


[1]: http://xml.apache.org/cocoon/howto/howto-paginator-transformer.html
[2]: 
http://developer.java.sun.com/developer/technicalArticles/javaserverpages/cachedrowset/


-- 
Ugo Cei - Consorzio di Bioingegneria e Informatica Medica
P.le Volontari del Sangue, 2 - 27100 Pavia - Italy
Phone: +39.0382.525100 - E-mail: u.cei@cbim.it


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

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


RE: how to write data to the XML file which the data is read from ?

Posted by Ryan Agler <ry...@hotmail.com>.
If you're using Xalan, there is an XSLT extension that will let you do
this.  You could embed the code to save changes in the same XSL file you
use for presentation, depending on a request parameter.

<map:generate src="docs/yourXMLfile.xml"/>
   <map:transform src="stylesheets/xalanStylesheet.xsl">
    <map:parameter name="use-request-parameters" value="true"/>
   </map:transform>
<map:serialize/>


xalanStylesheet.xsl would look something like this:

<?xml version="1.0"?>
<xsl:stylesheet  exclude-result-prefixes="*"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="org.apache.xalan.xslt.extensions.Redirect"
extension-element-prefixes="xalan" version="1.0">
   <xsl:strip-space elements="*" />
   <xsl:output method="xml" indent="yes" otput:indent-amount="5"
xmlns:otput="http://xml.apache.org/xslt" />
   <xsl:param name="save"/>
   <xsl:param name="mytext"/>
   <xsl:template match="/mydoc">
      <html>
         <xsl:choose>
            <xsl:when test="$save = '1'">
               <xsl:variable name="file"
select="concat('../docs/','yourXMLfile.xml')"/>
               <xalan:write select="$file">
	            <mydoc>
                     <mytext><xsl:value-of select="$mytext"/></mytext>
	            </mydoc>
               </xalan:write>
               <p><xsl:value-of select="$mytext"/></p>
            </xsl:when>
            <xsl:otherwise>
               <p><xsl:value-of select="mytext"/></p>
            </xsl:otherwise>
         </xsl:choose>
      </html>
   </xsl:template>
</xsl:stylesheet>


good luck


-----Original Message-----
From: Vadim Gritsenko [mailto:vadim.gritsenko@verizon.net] 
Sent: Wednesday, September 18, 2002 6:46 AM
To: cocoon-users@xml.apache.org
Subject: Re: how to write data to the XML file which the data is read
from ?

funing wrote:

>Hi! all:
>  I am a newbie on cocoon and xsp. I want to know if it is possible 
>to  write data to the XML file which the data is read from. That means,
>I can get some data from a xml file, and transform it to a html and
>present it to a user. The user may change the data. How can I save the 
>changes to the VERY xml which the data comes from?
>
>  I think serializer may be the answer. But I don't know how to
generate
>a xml file dynamically without http response.
>

See <slash-edit/> demo. It's under mount/edit in the scratchpad/webapp.

Vadim


>best regards
>  
>




---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.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/faq/index.html>

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


Re: how to write data to the XML file which the data is read from ?

Posted by Vadim Gritsenko <va...@verizon.net>.
funing wrote:

>Hi! all:
>  I am a newbie on cocoon and xsp. I want to know if it is possible 
>to  write data to the XML file which the data is read from. That means,
>I can get some data from a xml file, and transform it to a html and
>present it to a user. The user may change the data. How can I save the 
>changes to the VERY xml which the data comes from?
>
>  I think serializer may be the answer. But I don't know how to generate
>a xml file dynamically without http response.
>

See <slash-edit/> demo. It's under mount/edit in the scratchpad/webapp.

Vadim


>best regards
>  
>




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

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


how to write data to the XML file which the data is read from ?

Posted by funing <fu...@necas.nec.co.jp>.
Hi! all:
  I am a newbie on cocoon and xsp. I want to know if it is possible 
to  write data to the XML file which the data is read from. That means,
I can get some data from a xml file, and transform it to a html and
present it to a user. The user may change the data. How can I save the 
changes to the VERY xml which the data comes from?

  I think serializer may be the answer. But I don't know how to generate
a xml file dynamically without http response.


best regards


-- 
funing <fu...@necas.nec.co.jp>


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

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