This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new c90e92dada3 CAMEL-19889: camel-xslt - Add option 
allowTemplateFromHeader
c90e92dada3 is described below

commit c90e92dada37cf356537689d515794058389d51b
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Thu Sep 21 17:43:20 2023 +0200

    CAMEL-19889: camel-xslt - Add option allowTemplateFromHeader
---
 .../src/main/docs/xslt-saxon-component.adoc        | 30 +++++++++++++++++++---
 .../camel-xslt/src/main/docs/xslt-component.adoc   | 28 ++++++++++++++++++--
 2 files changed, 53 insertions(+), 5 deletions(-)

diff --git 
a/components/camel-xslt-saxon/src/main/docs/xslt-saxon-component.adoc 
b/components/camel-xslt-saxon/src/main/docs/xslt-saxon-component.adoc
index 3a7fcc343b9..d7f2640033e 100644
--- a/components/camel-xslt-saxon/src/main/docs/xslt-saxon-component.adoc
+++ b/components/camel-xslt-saxon/src/main/docs/xslt-saxon-component.adoc
@@ -90,7 +90,7 @@ To make the parameters useable, you will need to declare them.
 [source,xml]
 ----
 <setHeader name="myParam"><constant>42</constant></setHeader>
-<to uri="xslt:MyTransform.xsl"/>
+<to uri="xslt-saxon:MyTransform.xsl"/>
 ----
 
 The parameter also needs to be declared in the top level of the XSLT for it to 
be
@@ -195,9 +195,33 @@ With Spring XML:
 
 == Dynamic stylesheets
 
-To provide a dynamic stylesheet at runtime you can define a dynamic URI.
-See xref:manual:faq:how-to-use-a-dynamic-uri-in-to.adoc[How to use a dynamic 
URI in
+To provide a dynamic stylesheet at runtime you can either
+
+- Define a dynamic URI. See 
xref:manual:faq:how-to-use-a-dynamic-uri-in-to.adoc[How to use a dynamic URI in
 to()] for more information.
+- Use header with the stylesheet.
+
+When using a header for dynamic stylesheet, then you can either refer to the 
stylesheet as a `file` or `classpath`
+with the header `CamelXsltResourceUri`, such as:
+
+[source,java]
+----
+from("direct:transform")
+    .setHeader("CamelXsltResourceUri", 
simple("file:styles/${header.region}.xsl"))
+    .to("xslt-saxon:template.xsl?allowTemplateFromHeader=true");
+----
+
+Here we set the `CamelXsltResourceUri` header to refer to a stylesheet to be 
loaded from the file system,
+with a dynamic name that is computed from another header (`region`).
+
+Notice how the `allowTemplateFromHeader` must be set to `true` on the XSLT 
endpoint to support dynamic templates.
+
+You can also use the header `CamelXsltStylesheet` which instead should contain 
the content of the stylesheet
+to use, instead of referring to a file as the example from above.
+
+TIP: You can set `contentCache=false` and refer to a non-existing template, 
such as `"xslt-saxon:dummy.xsl?contentCache=false&allowTemplateFromHeader=true"`
+as this will tell Camel to not load `dummy.xsl` on startup but to load the 
stylesheet on demand. And because you
+provide the stylesheet via headers then its fully dynamic.
 
 == Accessing warnings, errors and fatalErrors from XSLT ErrorListener
 
diff --git a/components/camel-xslt/src/main/docs/xslt-component.adoc 
b/components/camel-xslt/src/main/docs/xslt-component.adoc
index d10269aaf7b..d54457e5659 100644
--- a/components/camel-xslt/src/main/docs/xslt-component.adoc
+++ b/components/camel-xslt/src/main/docs/xslt-component.adoc
@@ -158,9 +158,33 @@ You can explicitly specify `file:` or `classpath:` 
loading. The two loading type
 
 == Dynamic stylesheets
 
-To provide a dynamic stylesheet at runtime you can define a dynamic URI.
-See xref:manual:faq:how-to-use-a-dynamic-uri-in-to.adoc[How to use a dynamic 
URI in
+To provide a dynamic stylesheet at runtime you can either
+
+- Define a dynamic URI. See 
xref:manual:faq:how-to-use-a-dynamic-uri-in-to.adoc[How to use a dynamic URI in
 to()] for more information.
+- Use header with the stylesheet.
+
+When using a header for dynamic stylesheet, then you can either refer to the 
stylesheet as a `file` or `classpath`
+with the header `CamelXsltResourceUri`, such as:
+
+[source,java]
+----
+from("direct:transform")
+    .setHeader("CamelXsltResourceUri", 
simple("file:styles/${header.region}.xsl"))
+    .to("xslt:template.xsl?allowTemplateFromHeader=true");
+----
+
+Here we set the `CamelXsltResourceUri` header to refer to a stylesheet to be 
loaded from the file system,
+with a dynamic name that is computed from another header (`region`).
+
+Notice how the `allowTemplateFromHeader` must be set to `true` on the XSLT 
endpoint to support dynamic templates.
+
+You can also use the header `CamelXsltStylesheet` which instead should contain 
the content of the stylesheet
+to use, instead of referring to a file as the example from above.
+
+TIP: You can set `contentCache=false` and refer to a non-existing template, 
such as `"xslt:dummy.xsl?contentCache=false&allowTemplateFromHeader=true"`
+as this will tell Camel to not load `dummy.xsl` on startup but to load the 
stylesheet on demand. And because you
+provide the stylesheet via headers then its fully dynamic.
 
 == Accessing warnings, errors and fatalErrors from XSLT ErrorListener
 

Reply via email to