Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于参数的XSLT动态求和_Xslt_Xml Parsing_Apache Camel_Xslt 2.0 - Fatal编程技术网

基于参数的XSLT动态求和

基于参数的XSLT动态求和,xslt,xml-parsing,apache-camel,xslt-2.0,Xslt,Xml Parsing,Apache Camel,Xslt 2.0,我从ApacheCamel调用这个XSL,并将消息头设置为参数,但仍然没有得到结果 我想要一个XSLT,它根据一个参数给我求和。问题是参数可以是多个值,也可以是一个值 <EmpJob> <EmpJob> <userId>testID</userId> <EmpPayCompRecurring> <payComponent>1010</payComponent> &l

我从ApacheCamel调用这个XSL,并将消息头设置为参数,但仍然没有得到结果

我想要一个XSLT,它根据一个参数给我求和。问题是参数可以是多个值,也可以是一个值

<EmpJob>
<EmpJob>
<userId>testID</userId>
<EmpPayCompRecurring>
            <payComponent>1010</payComponent>
            <endDate>2020-06-30T00:00:00.000</endDate>
            <paycompvalue>3025.67</paycompvalue>
            <userId>testID</userId>
            <currencyCode>EUR</currencyCode>
            <startDate>2020-06-01T00:00:00.000</startDate>
        </EmpPayCompRecurring>
 <EmpPayCompRecurring>
            <payComponent>6097</payComponent>
            <endDate>2019-12-31T00:00:00.000</endDate>
            <paycompvalue>100.0</paycompvalue>
            <userId>testID</userId>
            <currencyCode>EUR</currencyCode>
            <startDate>2018-12-06T00:00:00.000</startDate>
        </EmpPayCompRecurring>
</EmpJob>
</EmpJob>

睾丸
1010
2020-06-30T00:00:00.000
3025.67
睾丸
欧元
2020-06-01T00:00:00.000
6097
2019-12-31T00:00:00.000
100
睾丸
欧元
2018-12-06T00:00:00.000
我创建了一个XSLT转换

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name = "custReturnDate" />
    <xsl:template match="/EmpJob">
        
         <xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="payrecur">'1010','6097' </xsl:variable>

     <mainroot>
     <xsl:for-each select="EmpJob">
            <root>
                    <__metadata>
                      
                        <uri><xsl:value-of select="concat('EmpCompensation(seqNumber=1L,startDate=datetime',$apos ,$custReturnDate, $apos,',userId=',$apos,userId,$apos,')')"/></uri>
                    </__metadata>
                  
                    <customDouble13><xsl:value-of select="sum(EmpPayCompRecurring[$payrecur]/paycompvalue) "/></customDouble13>

                </root>
           
     
        </xsl:for-each>
    </mainroot>
    </xsl:template>
</xsl:stylesheet>

'
'1010','6097' 
“payrecur”应该是稍后的参数,根据该参数,我应该对节点值求和


另外,我可以将参数更改为任何值,因为我是从代码调用模板的。

给定XSLT 2或3,我会将参数声明为字符串或整数序列,然后比较
sum(empPayComprecuring[payComponent=$payrecur]/paycompvalue)

所以声明,例如

一个最小的样式表是

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:param name = "custReturnDate" />
    
    <xsl:param name="payrecur" as="xs:string*" select="'1010','6097'"/>
    
    <xsl:output indent="yes"/>
    
    <xsl:template match="/EmpJob">
        
         <xsl:variable name="apos">'</xsl:variable>

     <mainroot>
     <xsl:for-each select="EmpJob">
            <root>
                    <__metadata>
                      
                        <uri><xsl:value-of select="concat('EmpCompensation(seqNumber=1L,startDate=datetime',$apos ,$custReturnDate, $apos,',userId=',$apos,userId,$apos,')')"/></uri>
                    </__metadata>
                  
                    <customDouble13>
                        <xsl:value-of select="sum(EmpPayCompRecurring[payComponent = $payrecur]/paycompvalue)"/>
                        </customDouble13>

                </root>
           
     
        </xsl:for-each>
    </mainroot>
    </xsl:template>
</xsl:stylesheet>

'

我得到了3125.67。您可能需要在
xsl:stylesheet
元素上添加
exclude result prefixes=“#all”

大家好,以防有人遇到我在添加标题中的参数之前提到的这种情况,以便XSLT模板能够获得它。不幸的是,模板将其作为字符串接收,因此我必须使用函数tokenize()将参数转换为数组,然后才能使用Martin Honnen提供的模板

此场景将适用于ApacheCamel和SAP CPI

致以最诚挚的问候

Ibrahim

谢谢你的回答,我按照你提到的那样做了,但是我得到了一个异常“net.sf.saxon.s9api.SaxonApiException”,你能从你这边测试一下吗?如何从命令行或使用Java代码运行它?你能编辑你的问题并在那里显示细节吗?您需要将前缀
xs
声明为
xmlns:xs=”http://www.w3.org/2001/XMLSchema“
在您的样式表中。谢谢,我添加了前缀,现在我没有收到任何异常,我是从Apache Camel调用它的,我输入了参数“'1010','6097'”,但得到的是零值。我甚至再次展示了它,以确保它是正确的,而且确实是这样this@Ibrahim,我用一个更完整的示例编辑了答案,以及使用Saxon 9.8 HE运行时得到的总和结果。我不知道Camel以及您如何在那里设置参数,如果问题发生在该上下文中,您可能希望为Camel添加标记。谢谢它确实可以工作,但使用Camel它不是。我还为Camel添加了一个标记谢谢您的帮助您也可以在此处添加骆驼路线吗?