添加两个xmls。使用XSLT转换器

时间:2012-10-26 19:02:25

标签: java xml xslt mule

我正在为一个令我困扰的场景寻找解决方案。

我正在研究mule 3.3。

我有一些传入的XML和第二个来自richher的XMLcoming。

现在来自richser的xml将被添加到我的输入XML中。

我的流程如下(摘要)

<flow name="main" >
    <file:inbound  ....> 
    <enricher target="#[variable:myProperty]">
        <vm:outbound .... />
    </enricher>

    <xslt transformer .... />
    .......
    .......
    <file:outbound ..>
</flow>

My Mule Flow部分和下面给出的XSL

    <mulexml:xslt-transformer   maxIdleTransformers="2" maxActiveTransformers="5"   xsl-file="C:\NSBTransformerXSL.xsl" outputEncoding="UTF-8" doc:name="XSLT">


        <mulexml:context-property key="RefXML"  value="#[header:INVOCATION:RefXML]" />
    </mulexml:xslt-transformer>

我的XSL在下面给出

<xsl:param name="RefXML"></xsl:param>

<xsl:template match="@*|node()">        
    <xsl:copy   >             
        <xsl:apply-templates select="@*|node()"/>                  
    </xsl:copy>    
</xsl:template>

<xsl:template match="TXRequest">
    <xsl:copy copy-namespaces="no" >
        <xsl:apply-templates select="@* | node()"/>         
        <xsl:copy-of select="$RefXML"/>                         
    </xsl:copy>
</xsl:template>

谢谢..

3 个答案:

答案 0 :(得分:2)

使用XSL-T转换器并将您从richser获得的XML片段作为命名参数传递给XSL。

通过这种方式,您可以轻松组合两个XML。

执行此操作的正确方法是将RefXML解析为DOM元素,然后将其作为XSL参数传递,但a bug in Mule会阻止此:(

因此,唯一的选择是RefXML的字符串值的逐字副本:

<xsl:value-of select="$RefXML" disable-output-escaping="yes" />

不是很满意,但它确实有效。

答案 1 :(得分:0)

目前尚不清楚您的问题是什么。我相信你很难将这两个xml碎片结合起来。

如果是这种情况,我建议使用Datamapper -http://www.mulesoft.org/documentation/display/MULE3STUDIO/DataMapper+Transformer+Reference

尝试在你的问题中具体说明,也有人想问你正在做什么版本的骡子。(希望我能把这篇文章作为评论)

答案 2 :(得分:0)

您也可以使用saxon:parse extension。以下适用于我:

<xsl:param name="RefXMLIn"/>
<xsl:variable name="RefXML" select="saxon:parse($RefXMLIn)" xmlns:saxon="http://saxon.sf.net/"/>

它将接收XML的参数重命名为文本,并使用解析函数的结果填充原始变量。

此扩展名是Saxon特有的,但Saxon是Mule附带的默认XML库。

相关问题