cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robby Pelssers <>
Subject RE: [C2.2] Get Element from uploaded file
Date Fri, 18 Nov 2011 09:29:08 GMT
I just published a little write-up about a similar use case as you described on

Kind regards,

From: Matthias Müller []
Sent: Friday, November 18, 2011 8:34 AM
Subject: Re: [C2.2] Get Element from uploaded file

I extended your first approach:

in the flow script I use the inputStream from the uploaded file to feed a XpathEvaluator class
in combination with the an xpath expression.

var inputStream = widget.getValue().getInputStream();
var xpath = "/my/path/to/element";
var result = cocoon.getComponent('XPathEvaluator').evaluate(inputStream, xpath);

Thanks again, Matthias

Von: Robby Pelssers <>
An: Matthias Müller <>; "" <>
Gesendet: 16:22 Donnerstag, 17.November 2011
Betreff: RE: [C2.2] Get Element from uploaded file
I actually had a similar need the other week and while I have used some XML-JAVA mappers like
Castor and XStream in the past I decided to try another approach where I generated JSON which
can be used from flowscript:

/** flowscript function to generate the pdf **/

function json2Object(json) {
                return eval("(" + json + ")");

function generatePDF() {
    var id =;  //e.g. PH3330L

    //var fileName = cocoon.getComponent('fileNameExtractor').getFileName(id);

    var output = new;

    var uri = "extractData/" + id;
    //now we invoke a pipeline which returns a JSON string. E.g:
     *   {"id": "PH3330L","fileName": "PH3330L.pdf"},
    cocoon.processPipelineTo(uri, null, output);

    var responseData = json2Object(output.toString());

    var response = cocoon.response;
                "attachment; filename=" + responseData.fileName;
    cocoon.sendPage('source2pdf/' + id);


  {1} id: unique identifier for the source xml used to generate the PDF
<map:match pattern="generatePdf/*">
  <map:call function="generatePDF">
    <map:parameter name="id" value="{1}"/>

<map:match pattern="source2pdf/*">
  <map:generate src="source/{1}.xml"/> <!-- assume our sources are located in source
folder -->
  <map:transform src="xslt/source2poi.xslt"/>
  <map:serialize type="pdf"/>

  {1} id: unique identifier for the source xml used to generate the PDF
<map:match pattern="extractData/*">
  <map:generate src="source/{1}.xml"/>
  <map:transform src="extractData.xslt"/>
  <map:serialize type="json"/>  <!-- you can quickly test with @type="text" -->

/**** ExtractData.xslt will generate a JSON representation of the DATA needed ****/

<?xml version="1.0" encoding="UTF-8"?>
  Author: Robby Pelssers

<xsl:stylesheet version="2.0"

  <xsl:output method="text" version="1.0" encoding="UTF-8"/>

  <xsl:template match="/">
    <xsl:text>{"id": "</xsl:text><xsl:value-of select="someXpathExpr"/><xsl:text>",
"fileName: "</xsl:text><xsl:value-of select="someXpathExpr"/>"}<xsl:text></xsl:text>


View raw message