cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Johnston <>
Subject Re: Extract Document
Date Thu, 03 Aug 2006 04:28:14 GMT
Scott Warren wrote:
 > Can anyone give me a tip on the best way to extract a fragment of a
> document using xpath? The Fragment Extractor Transformer doesn't seem
> to do the job. Not that the documentation says much about what it
> does. I have tried an XSL using the EXSLT dyn:evaluate function but
> this fails. Note the xpath will come from parameters passed to the
 > pipeline.

In what way does dyn:evaluate fail?  I do think that may be the shortest 
path to what you're wanting.

I looked through the core components shipped with Cocoon and didn't see 
any that would evaluate an XPath out of the box.  XSLT would be ideal, 
except for the fact that you want to pass in the XPath as a parameter, 
so as you obviously realized the difficulty comes when trying to 
evaluate the passed-in string parameter as an XPath expression to select 
a nodeset.  This is exactly what dyn:evaluate is intended for so I think 
you're on the right track.

OK, I just gave it a quick try and the following XSLT worked just fine:

<xsl:stylesheet version="1.0"

   <xsl:param name="xpath" />

   <xsl:template match="/">
     <xsl:copy-of select="dyn:evaluate($xpath)" />



<map:transform src="extract.xsl">
   <map:parameter name="xpath" value="/my/xpath/expression" />

If your xpath will return more than one node then you should wrap it in 
a single parent element to maintain a valid XML document.

Let us know if you still have problems.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message