gpt4 book ai didi

java - 如何从Camel路由的xsl apply-templates中传递参数

转载 作者:行者123 更新时间:2023-12-01 09:20:04 25 4
gpt4 key购买 nike

我想将 xPath 从 Camel 路由传递到 XSLT 转换,并在 apply-templates select 中使用它。根据 Camel 文档,我已将参数设置为 Header 并在 XSLT 转换中声明它。我正在使用 xslt 2.0

我可以看到 xPath 的值,但我无法在 apply-templates select 中工作。有关详细信息,请参阅示例:

路由.java

from("direct:myRoute")
.setHeader("myParam", constant("/myxPath/example")
.to(XSLT_PATH);

xslt.xml

<xsl:param name="myParam"/>
<xsl:template match="/">
<xsl:element name="DummyElement">
<xsl:element name="ChildElement">
</xsl:element>
<xsl:value-of select="$myParam"/> - this will return provided xpath (/myxPath/example)
<xsl:apply-templates select="$myParam" - this doesn't work
mode="mymode"/>
</xsl:element>
</xsl:template>

我也用变量进行了测试,但它也不起作用:

<xsl:param name="myParam"/>
<xsl:variable name="myVariable" select="$myParam"/> - change here
<xsl:template match="/">
<xsl:element name="DummyElement">
<xsl:element name="ChildElement">
</xsl:element>
<xsl:apply-templates select="$myVariable" - change here
mode="mymode"/>
</xsl:element>
</xsl:template>

但是当我在参数中提供 xpath 时,选择所有内容都工作正常:

<xsl:param name="myParam" select="/myxPath/example"/> -change here
<xsl:variable name="myVariable" select="$myParam"/>
<xsl:template match="/">
<xsl:element name="DummyElement">
<xsl:element name="ChildElement">
</xsl:element>
<xsl:apply-templates select="$myVariable"
mode="mymode"/>
</xsl:element>
</xsl:template>

我查看了已经存在的主题,但没有得到解决方案。提前致谢!

最佳答案

默认情况下,Camel 消息中的所有 header 都可以在 XSLT 中使用。就我而言,我需要将新 header 放入我的消息中:

.setHeader("myParam", constant("/myxPath/example"))

我在 XSLT 中正确获取了 myParam。然而,根据“@Martin Honnen”和@Orabîg 评论,Camel 将这些参数作为字符串传递,因此在 XSLT 中我收到了:

<xsl:param name="myParam" select="'/myxPath/example'"/> - note additional single quotation mark 

在 XSLT 2.0 中,无法将 xsl:param 值从字符串直接转换为 xpath。

关于java - 如何从Camel路由的xsl apply-templates中传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40220720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com