On 1/8/09, Anish <[email protected]> wrote: > [email protected] wrote: > On 1/5/09, Anish <[email protected]> wrote: > Andreas Hartmann wrote: > Hi Anish, > Anish schrieb: > I want to write XML file physically on the server using xsl tags: > would you mind giving a larger context about what you're trying to > achieve? Do you want to modify files in the Lenya repository? Which Lenya > version are you using? > -- Andreas > > I tried but it didn't work (as I need to apply for XSLT 1.0). Also I'm > not sure whether these tags create new files physically on the file system > or not. > I need to do this for XSLT 1.0. > Please suggest. > > Hi Andreas > > Actually I want to write a new XML file (apart from Lenya's internal > files). This XML will reside on my server's file system as an independent > file. I'm using: > > 1) Lenya 1.2.4 > 2) Cocoon 2.1.7 > On Tomcat 5.5.17 > > -- > Thanks & Regards, > Anish > > To write the a portion of the current XML in a process to a file on > the hard drive, use the SourceWritingTransformer. > > Lenya 1.2's "default" Publication's publication-sitemap.xmap includes > a primitive cache using <map:transform type="write-source">. You will > need the surrounding code to add and remove tags for the > SourceWritingTransformer. The included addSourceTags.xsl and > removeSourceTags.xsl transformations write the entire XML to a file. > Possibilities include writing portions of the XML to different files. > The official documentation is at: > http://cocoon.apache.org/2.1/userdocs/sourcewriting-transformer.html > > solprovider > > I'm using the same and It's working but the problem is that it's not > appending the tags. It just replaces the whole file I need to append if the > tag doesn't exist. I want to achieve something like: > > <xsl:variable name="vid">aaa</xsl:variable> > <source:write > xmlns:source="http://apache.org/cocoon/source/1.0"> > > <source:insert create="true" overwrite="true"> > <source:source>trial.xml</source:source> > <source:path>/root</source:path> > > <source:replace>row[tid=$vid]/parent::*</source:replace> > <source:fragment> > <row> > <tid><xsl:value-of select="$vid"/></tid> > <name>HONEY</name> > </row> > </source:fragment> > </source:insert> > </source:write> > > I want to replace row tag with fragment (if tid corresponding to vid exists > otherwise create a new row tag in root). > > Please suggest. > Thanks & Regards, > Anish
Process: 1. Match: Receive request for change 2. Generate: Load XML (Maybe Aggregate with RequestGenerator?) 3. XSL Transform: Make changes. Adds tags for the SourceWritingTransformer if desired. 4. SourceWritingTransform: Save changes if "source" namespace elements are included. 5. XSL Transform: Remove any "source" elements and prepare report. 6. Serialize: Report results The "source:source" element specifies the file(s) to be written. Pass the filepath to Step 3 in the aggregated XML or use a parameter. Only create "source" elements if file(s) should be saved. You could try "source:insert"; may be broken so just replace the entire file if that does not work. The SourceWritingTransformer returns its input so Step 5 is needed to remove any "source" elements. Step 5 could report "Changes saved" or "No changes found." The critical concept is all decision-making happens in Step 3. Multiple XSLTs can be used; you do not need one XSLT to handle the entire process. Two XSLTs could be good to separate "row insertion" from "does the file need to be saved?": 1. Add new "row" elements with attribute "isChanged". 2. Check for any "isChanged" attributes. If one (or more) found, remove all "isChanged" attributes and add "source" elements. Otherwise just return the XML. Have you learned about "xsl:key"? Very useful for what you need. solprovider --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
