簡體   English   中英

如何從駱駝路線在xsl apply-templates中傳遞參數

[英]How to pass parameter in xsl apply-templates from Camel route

我想將xPath從Camel路由傳遞到XSLT轉換,並在apply-templates select使用它。 根據Camel文檔,我將參數設置為Header並在XSLT轉換中聲明它。 我正在使用xslt 2.0

我可以看到xPath的值,但不能在apply-templates select 請參閱示例以獲取詳細信息:

route.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>

我查看了已經存在的主題,但是沒有找到解決方案。 提前致謝!

默認情況下,來自駱駝消息的所有標頭在XSLT中都可用。 就我而言,我需要在消息中添加新的標頭:

.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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM