cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steven D. Majewski" <>
Subject How to obtain a xml from a xml file and a Xpath expression
Date Mon, 14 Apr 2008 21:41:23 GMT

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  

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

In my sitemap is:

       <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:transform type="xinclude" />

         <map:serialize type="xml" />

[ ** 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=""  

  <xi:include href="../published/${cocoon.parameters.instdir}/$ 


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  

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}/$ 
   parse="xml" xpointer="xpointer(/${cocoon.parameters.path})"

[ You could also use the JXP XPATH API directly from flowscript/ 
   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:
For additional commands, e-mail:

View raw message