You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Carlos Tejo Alonso <ca...@fundacionctic.org> on 2008/04/14 13:43:57 UTC

How to obtain a xml from a xml file and a Xpath expression

Hello,

I was doing some research about how to obtain a xml from a xml file + an XPATH expression in Cocoon, but I haven't found any information really clear. Is there any parameter to add into a generator, or a transformer or something that can do that issue?

Cheers,

Carlos Tejo Alonso
Departamento de I+D+i - Fundación CTIC
Parque Científico Tecnológico Gijón, Asturias (Spain)
www.fundacionctic.org

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


How to obtain a xml from a xml file and a Xpath expression

Posted by "Steven D. Majewski" <sd...@virginia.edu>.
On Apr 14, 2008, at 7:43 AM, Carlos Tejo Alonso wrote:
> Hello,
>
> I was doing some research about how to obtain a xml from a xml file  
> + an XPATH expression in Cocoon, but I haven't found any  
> information really clear. Is there any parameter to add into a  
> generator, or a transformer or something that can do that issue?
>

It does seem odd to me that there isn't a simple xpath transformer or  
generator in cocoon,
but in any case there do seem to be several ways to do the equivalent  
thing.

I've been trying to do this by using JX to generate an xml file with  
an xinclude statement
with the file and an xpointer fragment identifier, and then running  
it thru the xinclude
transformer.


In my sitemap is:

     <map:pipeline>
       <map:match pattern="xpath/*/*/**">
         <map:generate type="jx" src="scripts/xpath.jx" >

           <map:parameter name="instdir" value="{1}" />
           <map:parameter name="file" value="{2}" />
           <map:parameter name="path" value="/{3}" />
         </map:generate>

         <map:transform type="xinclude" />

         <map:serialize type="xml" />
       </map:match>
     </map:pipeline>


[ ** I believe I have type="jx" redefined to use "newjx"
      so I didn't have to change all of my sitemaps. ** ]


The jx template file ( xpath.jx ) contains:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"  
xmlns:xi="http://www.w3.org/2001/XInclude">

  <xi:include href="../published/${cocoon.parameters.instdir}/$ 
{cocoon.parameters.file}#xpointer(/${cocoon.parameters.path})"
    />

</fragment>



And, given a valid file and xpath expression, it works properly
( yielding the value of the xpointer expression wrapped in  
<fragment>...</fragment> tags )
except that (using cocoon 2.1.11) I get the following deprecation  
warning:


WARN  (2008-04-14) 16:26.33:681 [sitemap.transformer.xinclude] (/ 
cocoon/vivaead/xpath/odu/vino00012.xml/eadheader/eadid) http-8080- 
Processor23/XIncludeTransformer.XIncludePipe: Fragment identifer  
found in 'href' attribute: ../published/odu/vino00012.xml#xpointer(// 
eadheader/eadid)Fragment identifiers are forbidden by the XInclude  
specification. They are still handled by XIncludeTransformer for  
backward compatibility, but their use is deprecated and will be  
prohibited in a future release.  Use the 'xpointer' attribute instead.



Changing the xinclude to use a xpointer attribute, instead of a  
xpointer #fragment-id eliminates that warning:


<xi:include href="../published/${cocoon.parameters.instdir}/$ 
{cocoon.parameters.file}"
   parse="xml" xpointer="xpointer(/${cocoon.parameters.path})"
  />




[ You could also use the JXP XPATH API directly from flowscript/ 
javaflow,
   and you could also probably pass a DOM or some other object model  
to jx transformer. ]


-- Steve Majewski / UVA Alderman Library









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


Re: How to obtain a xml from a xml file and a Xpath expression

Posted by Reinhard Haller <re...@interactive-net.de>.
Hi Carlos,

Carlos Tejo Alonso schrieb:
> Thanks for the suggestions. I wonder if there is one transformer where you indicate the file and the XPATH expression and gives you the new xml file.
>   
try it with a xpath generator (you can specify your file directly or via 
pattern matching), followed by a source-writing-transform.

http://cocoon.apache.org/2.1/userdocs/xpathdirectory-generator.html

http://cocoon.apache.org/2.1/userdocs/sourcewriting-transformer.html


Regards,
Reinhard


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


RE: How to obtain a xml from a xml file and a Xpath expression

Posted by Carlos Tejo Alonso <ca...@fundacionctic.org>.
Heelo,


> > I wanted to explain thi situation:
> > I have a file called example.xml and I want to apply a XPATH  
> > expression in order to obtain another file called example-2.xml  
> > with the elements selected by the XPATH expression.
> >
> >> For one you could just generate your file, apply an xslt with
> >> an xpath expression or otherwise use the Xquery generator[1].
> >
> > Thanks for the suggestions. I wonder if there is one transformer  
> > where you indicate the file and the XPATH expression and gives you  
> > the new xml file.
> >
> > Did I explain myself better? Sorry for my awful English :S
> >
> Did you literally mean that you want to produce another XML file in  
> the filesystem ?
> ( which, I guess, is why Reinhard suggests using the sourcewriting  
> transformer )
> Or did you just want to extract that xml fragment and transform 
> +serialize it in the pipeline?

I am wondering if it is possible the second option in Cocoon,

Carlos Tejo

 
> -- Steve Majewski
> 
> 
> >
> > On Apr 14, 2008, at 12:26 PM, Reinhard Haller wrote:
> >>
> >> Hi Carlos,
> >>
> >> Carlos Tejo Alonso schrieb:
> >>> Thanks for the suggestions. I wonder if there is one transformer  
> >>> where you indicate the file and the XPATH expression and gives  
> >>> you the new xml file.
> >>>
> >> try it with a xpath generator (you can specify your file directly  
> >> or via pattern matching), followed by a source-writing-transform.
> >>
> >> http://cocoon.apache.org/2.1/userdocs/xpathdirectory-generator.html
> >>
> >> 
> http://cocoon.apache.org/2.1/userdocs/sourcewriting-transformer.html
> >>

Carlos Tejo Alonso
Departamento de I+D+i - Fundación CTIC
Parque Científico Tecnológico Gijón, Asturias (Spain)
www.fundacionctic.org

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


Re: How to obtain a xml from a xml file and a Xpath expression

Posted by "Steven D. Majewski" <sd...@virginia.edu>.
On Apr 14, 2008, at 11:52 AM, Carlos Tejo Alonso wrote:
> Hi Jeroen,
>
>> Hi Carlos,
>>
>> I'm not really sure what you mean with XML from an XML. Where
>> do you try to obtain this XML.
>
> I wanted to explain thi situation:
> I have a file called example.xml and I want to apply a XPATH  
> expression in order to obtain another file called example-2.xml  
> with the elements selected by the XPATH expression.
>
>> For one you could just generate your file, apply an xslt with
>> an xpath expression or otherwise use the Xquery generator[1].
>
> Thanks for the suggestions. I wonder if there is one transformer  
> where you indicate the file and the XPATH expression and gives you  
> the new xml file.
>
> Did I explain myself better? Sorry for my awful English :S
>

Did you literally mean that you want to produce another XML file in  
the filesystem ?
( which, I guess, is why Reinhard suggests using the sourcewriting  
transformer )
Or did you just want to extract that xml fragment and transform 
+serialize it in the pipeline?

-- Steve Majewski


>
> On Apr 14, 2008, at 12:26 PM, Reinhard Haller wrote:
>>
>> Hi Carlos,
>>
>> Carlos Tejo Alonso schrieb:
>>> Thanks for the suggestions. I wonder if there is one transformer  
>>> where you indicate the file and the XPATH expression and gives  
>>> you the new xml file.
>>>
>> try it with a xpath generator (you can specify your file directly  
>> or via pattern matching), followed by a source-writing-transform.
>>
>> http://cocoon.apache.org/2.1/userdocs/xpathdirectory-generator.html
>>
>> http://cocoon.apache.org/2.1/userdocs/sourcewriting-transformer.html
>>
>>
>> Regards,
>> Reinhard
>>

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


RE: How to obtain a xml from a xml file and a Xpath expression

Posted by Carlos Tejo Alonso <ca...@fundacionctic.org>.
Hi Jeroen,

> Hi Carlos,
> 
> I'm not really sure what you mean with XML from an XML. Where 
> do you try to obtain this XML.

I wanted to explain thi situation:
I have a file called example.xml and I want to apply a XPATH expression in order to obtain another file called example-2.xml with the elements selected by the XPATH expression.

> For one you could just generate your file, apply an xslt with 
> an xpath expression or otherwise use the Xquery generator[1].

Thanks for the suggestions. I wonder if there is one transformer where you indicate the file and the XPATH expression and gives you the new xml file.

Did I explain myself better? Sorry for my awful English :S

Regards,


Carlos Tejo Alonso
Departamento de I+D+i - Fundación CTIC
Parque Científico Tecnológico Gijón, Asturias (Spain)
www.fundacionctic.org

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


RE: How to obtain a xml from a xml file and a Xpath expression

Posted by Jeroen Reijn <j....@onehippo.com>.
Hi Carlos,

I'm not really sure what you mean with XML from an XML. Where do you try to obtain this XML.

For one you could just generate your file, apply an xslt with an xpath expression or otherwise use the Xquery generator[1].

Regards,

Jeroen

[1]http://cocoon.apache.org/2.1/userdocs/xinclude-transformer.html




-----Original Message-----
From: Carlos Tejo Alonso [mailto:carlos.tejo@fundacionctic.org]
Sent: Mon 4/14/2008 1:43 PM
To: users@cocoon.apache.org
Subject: How to obtain a xml from a xml file and a Xpath expression
 
Hello,

I was doing some research about how to obtain a xml from a xml file + an XPATH expression in Cocoon, but I haven't found any information really clear. Is there any parameter to add into a generator, or a transformer or something that can do that issue?

Cheers,

Carlos Tejo Alonso
Departamento de I+D+i - Fundación CTIC
Parque Científico Tecnológico Gijón, Asturias (Spain)
www.fundacionctic.org

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