Class XsltAggregationStrategy

java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.component.xslt.XsltAggregationStrategy
All Implemented Interfaces:
AutoCloseable, org.apache.camel.AggregationStrategy, org.apache.camel.CamelContextAware, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.HasCamelContext, org.apache.camel.StatefulService, org.apache.camel.SuspendableService

public class XsltAggregationStrategy extends org.apache.camel.support.service.ServiceSupport implements org.apache.camel.AggregationStrategy, org.apache.camel.CamelContextAware
The XSLT Aggregation Strategy enables you to use XSL stylesheets to aggregate messages.

Since XSLT does not directly support providing multiple XML payloads as an input, this aggregator injects the new incoming XML document (newExchange) into the oldExchange as an exchange property of type Document. The old exchange therefore remains accessible as the root context. This exchange property can then be accessed from your XSLT by declaring an <xsl:param /> at the top of your stylesheet: <xsl:param name="new-exchange" /> <xsl:template match="/"> <xsl:copy-of select="/ElementFromOldExchange" /> <xsl:copy-of select="$new-exchange/ElementFromNewExchange" /> </xsl:template> The exchange property name defaults to new-exchange but can be changed through setPropertyName(String).

Some code bits have been copied from the XsltEndpoint.

  • Constructor Details

    • XsltAggregationStrategy

      public XsltAggregationStrategy(String xslFileLocation)
      Constructor.
      Parameters:
      xslFileLocation - location of the XSL transformation
  • Method Details

    • getCamelContext

      public org.apache.camel.CamelContext getCamelContext()
      Specified by:
      getCamelContext in interface org.apache.camel.spi.HasCamelContext
    • setCamelContext

      public void setCamelContext(org.apache.camel.CamelContext camelContext)
      Specified by:
      setCamelContext in interface org.apache.camel.CamelContextAware
    • aggregate

      public org.apache.camel.Exchange aggregate(org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
      Specified by:
      aggregate in interface org.apache.camel.AggregationStrategy
    • setOutput

      public void setOutput(XsltOutput output)
    • setXslt

      public void setXslt(XsltBuilder xslt)
    • setUriResolver

      public void setUriResolver(URIResolver uriResolver)
    • setTransformerFactoryClass

      public void setTransformerFactoryClass(String transformerFactoryClass)
    • setTransformerFactory

      public void setTransformerFactory(TransformerFactory transformerFactory)
    • getPropertyName

      public String getPropertyName()
    • setPropertyName

      public void setPropertyName(String propertyName)
    • configureOutput

      protected void configureOutput(XsltBuilder xslt, String output) throws Exception
      Throws:
      Exception
    • loadResource

      protected void loadResource(String resourceUri) throws TransformerException, IOException
      Loads the resource.
      Parameters:
      resourceUri - the resource to load
      Throws:
      TransformerException - is thrown if error loading resource
      IOException - is thrown if error loading resource
    • create

      public static XsltAggregationStrategy create(String xslFile)
    • withPropertyName

      public XsltAggregationStrategy withPropertyName(String propertyName)
    • withOutput

      public XsltAggregationStrategy withOutput(XsltOutput output)
    • withUriResolver

      public XsltAggregationStrategy withUriResolver(URIResolver resolver)
    • withTransformerFactoryClass

      public XsltAggregationStrategy withTransformerFactoryClass(String clazz)
    • createXsltBuilder

      protected XsltBuilder createXsltBuilder()
    • doInit

      protected void doInit() throws Exception
      Overrides:
      doInit in class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class org.apache.camel.support.service.BaseService
      Throws:
      Exception