将参数传递给xslt作为Apache骆驼中的节点

时间:2018-10-24 08:42:54

标签: xslt apache-camel

是否可以将param作为节点而不作为字符串传递?

骆驼语境:

<setHeader headerName="document_as_node">
    <simple>${body}</simple>
</setHeader>

xslt:

<xsl:param name="document_as_node" />

body是一个xml文档,但是我将其作为字符串传递(尝试在xpath中使用此参数时出现错误)。如何将其作为节点传递或如何对其进行转换?

1 个答案:

答案 0 :(得分:0)

希望此示例会有所帮助:

from("timer:foo?period=30s")
            .setBody(constant("<oldWrapTag><someTag>123</someTag></oldWrapTag>"))
            .convertBodyTo(org.w3c.dom.Document.class)
            .setBody(xpath("//someTag"))
            .setHeader("insert", simple("body"))
            .to("xslt:/xslt/test.xsl")
            .to("log:body?showBody=true")
    ;

xslt:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="insert"/>

<xsl:template match="/">
    <xsl:element name="wrapTag">
        <xsl:copy-of select="$insert"/>
    </xsl:element>
</xsl:template>

输出:

2018-10-24 14:03:07,952 | INFO  | 10 - timer://foo | body                             | 247 - org.apache.camel.camel-core - 2.16.3 | Exchange[ExchangePattern: InOnly, BodyType: String, Body: <?xml version="1.0" encoding="UTF-8"?><wrapTag><someTag>123</someTag></wrapTag>]