You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sammm <ma...@gmail.com> on 2013/01/16 12:53:00 UTC

Dynamic XSL from Content

i'm new to Camel and have seen the example etc and the 'How do I use dynamic
URI in To' posting and infor on Expressions etc.
What i need to do, and cant quite work out how to do, is use the content of
the XML i wish to transform to derive the name of the XSL to use.
Essentially i have an existing JBI setup which does this:

  <saxon:xslt service="cvsrx1_0:requests-xslt" endpoint="requests-xslt">
    <saxon:expression>
      
      <bean
class="org.apache.servicemix.expression.JAXPStringXPathExpression">
      	
        <constructor-arg
value="concat(local-name(/*[local-name(.)='Envelope']/*[local-name(.)='Body']/*),'.xsl')"
/>
      </bean>
    </saxon:expression>
  </saxon:xslt>

The above is routed/reference like this:

  <eip:static-routing-slip service="cvsrx1_0:routing-slip"
endpoint="routing-slip">
    <eip:targets>
      <eip:exchange-target service="cvsrx1_0:requests-xslt" />
      <eip:exchange-target service="cvsrx1_0:rx-legacy-http" />
      <eip:exchange-target service="cvsrx1_0:responses-xslt" />
    </eip:targets>
  </eip:static-routing-slip>


where 'routing-slip' is passed a SOAP message.

So, use Camel DSL i *think* i could do something like

.to("xslt:${local-name(/*[local-name(.)='Envelope']/*[local-name(.)='Body']/*)}.xsl")

Can i do this, i.e use an XPath expression to derive the name of the XSL
from the XML/SOAP?

I saw that from 2.9 a header can be set, maybe thats the way to go - again
can that be doen using DSL?

Thanks for the help

Martin




--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-XSL-from-Content-tp5725634.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic XSL from Content

Posted by ericsodt <de...@ll.mit.edu>.
I am having a similar issue and cannot get my xslt route to use my custom
uriResolver.

I put into the headers the location of a webservice that will return back
the xsl:
 headers.put("templateLocation",
"http://localhost:8080/path/to/stylesheet");


then in my route try and do the following:
.recipientList(simple(header("templateLocation")+"?uriResolver=#emailResolver")


Any thoughts on how I might be able to dynamically load my xsl and process
it through the uri resolver?


Thanks!



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-XSL-from-Content-tp5725634p5736705.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic XSL from Content

Posted by sammm <ma...@gmail.com>.
Ok, worked it out - it was due to the XPath having already accessed the
'stream' before the XSL was used. adding streamCache ('<route
streamCache="true">') fixed it.

Martin



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-XSL-from-Content-tp5725634p5725755.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic XSL from Content

Posted by sammm <ma...@gmail.com>.
The above was working for a hard coded XSL name:

      <setHeader headerName="CamelXsltResourceUri">
	      <constant>META-INF/xsl/5.xsl</constant>
      </setHeader>
      <log message="CamelXsltResourceUri :
${header.CamelXsltResourceUri}"></log>
      <to uri="xslt:META-INF/xsl/dummy.xsl"/>


what i need to do i dynamically generate the name of the xsl:

      <setHeader headerName="CamelXsltResourceUri">
	      <xpath
resultType="java.lang.String">concat('META-INF/xsl/',//phar:pharmacyInfoRequest/pharmacyId/text(),'.xsl')</xpath>
      </setHeader>
      <to uri="xslt:META-INF/xsl/dummy.xsl"/>


when i use this i get this error:

javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException:
com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Premature end
of file.

i've enable trace and can see for both cases this message:

2013-01-18 06:55:55,482 [y_info/services] DEBUG SpringCamelContext            
- xslt://META-INF/xsl/5.xsl converted to endpoint:
Endpoint[xslt://META-INF/xsl/5.xsl] by component:
org.apache.camel.component.xslt.XsltComponent@163eae

The latter (dynamic case) then fails with the above 'end of file' exception.

Any ideas?

Many thanks

Martin





--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-XSL-from-Content-tp5725634p5725729.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic XSL from Content

Posted by sammm <ma...@gmail.com>.
Christian,
thats brilliant,
thanks
Martin



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-XSL-from-Content-tp5725634p5725681.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic XSL from Content

Posted by Christian Müller <ch...@gmail.com>.
XPath (put the name into a header) + recipientList + XSLT should work.

Best,
Christian
Am 16.01.2013 12:56 schrieb "sammm" <ma...@gmail.com>:

> i'm new to Camel and have seen the example etc and the 'How do I use
> dynamic
> URI in To' posting and infor on Expressions etc.
> What i need to do, and cant quite work out how to do, is use the content of
> the XML i wish to transform to derive the name of the XSL to use.
> Essentially i have an existing JBI setup which does this:
>
>   <saxon:xslt service="cvsrx1_0:requests-xslt" endpoint="requests-xslt">
>     <saxon:expression>
>
>       <bean
> class="org.apache.servicemix.expression.JAXPStringXPathExpression">
>
>         <constructor-arg
>
> value="concat(local-name(/*[local-name(.)='Envelope']/*[local-name(.)='Body']/*),'.xsl')"
> />
>       </bean>
>     </saxon:expression>
>   </saxon:xslt>
>
> The above is routed/reference like this:
>
>   <eip:static-routing-slip service="cvsrx1_0:routing-slip"
> endpoint="routing-slip">
>     <eip:targets>
>       <eip:exchange-target service="cvsrx1_0:requests-xslt" />
>       <eip:exchange-target service="cvsrx1_0:rx-legacy-http" />
>       <eip:exchange-target service="cvsrx1_0:responses-xslt" />
>     </eip:targets>
>   </eip:static-routing-slip>
>
>
> where 'routing-slip' is passed a SOAP message.
>
> So, use Camel DSL i *think* i could do something like
>
>
> .to("xslt:${local-name(/*[local-name(.)='Envelope']/*[local-name(.)='Body']/*)}.xsl")
>
> Can i do this, i.e use an XPath expression to derive the name of the XSL
> from the XML/SOAP?
>
> I saw that from 2.9 a header can be set, maybe thats the way to go - again
> can that be doen using DSL?
>
> Thanks for the help
>
> Martin
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Dynamic-XSL-from-Content-tp5725634.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>