我有一个场景,我将一个参数传递给XSLT,而XSLT又是一个xml元素。但它将作为逃逸字符发送(< for< ....)
我的要求是我有各种各样的子节点,我必须循环它们并需要转换。请找到请求,参数。
Request.xml
<retrievePaymentMethodsRequest>
<!--Optional:-->
<retrievePaymentMethodsRequestTO>
<financialAccountID>3</financialAccountID>
<bankCountryCode>1</bankCountryCode>
<clientID>12345</clientID>
<!--Optional:-->
<device>003</device>
<excludedLifeIndicator>003</excludedLifeIndicator>
<financialAccountStatus>3</financialAccountStatus>
<kindCode>003</kindCode>
<notEndedIndicator>0</notEndedIndicator>
<!--Optional:-->
<requestMode>003</requestMode>
<stateCode>003</stateCode>
</retrievePaymentMethodsRequestTO>
</retrievePaymentMethodsRequest>
参数xslt:
<b xmlns:fs2="somescheama" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fga="anyvalue"> xmlns:fs2="any value" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="any location ">
<statusCode>0</statusCode>
<errorMessage>errorMessage</errorMessage>
<paymentMethodTypes>
<!-- NULL or any type code 01, 04 , 10 (sample not real) -->
<methodTypeCode>01</methodTypeCode>
<!-- Possible values methodTypeDisplayName
CREDIT_CARD,BANK_ACCOUNT,CASH,CHECK,CASH_EQUIVALENT
-->
<methodTypeDisplayName>CREDIT_CARD</methodTypeDisplayName>
<!-- valid dollar amount -->
<maximumAmountPaid>100.00</maximumAmountPaid>
</paymentMethodTypes>
<paymentFormInfo>
<!-- NULL or any type code 01, 04 , 10 (sample not real) -->
<paymentMethodTypeCode>01</paymentMethodTypeCode>
<!-- sample form id 1004854 , 1004874 , 1004889 , 1004875-->
<formId>1004885</formId>
<!-- Not exactly sure just an assumption -->
<formLanguageRefId>US</formLanguageRefId>
<!-- forn name : EFT_AUTHORIZATION -->
<formName>EFT_AUTHORIZATION</formName>
<roleActivity>
<agentActivity>
<inOfficeRulesForActivity>
<!-- for Agent : REVIEW_PRINT, ESIGN , UPLOAD
for customer : CHECKBOX -->
<customerActivity>REVIEW_PRINT</customerActivity>
<customerRole>PAYOR</customerRole>
</inOfficeRulesForActivity>
<outOfOfficeRulesForActivity>
<customerActivity>CHECKBOX</customerActivity>
<customerRole>PAYOR</customerRole>
</outOfOfficeRulesForActivity>
</agentActivity>
<commonActivity>
<roleCategory>ONLINE</roleCategory>
<roleForActivity>
<customerActivity>ESIGN</customerActivity>
<customerRole>PAYOR</customerRole>
</roleForActivity>
</commonActivity>
</roleActivity>
</paymentFormInfo>
<financialAccountOwnerActivity>
<canChange>true</canChange>
<!-- valid String -->
<searchOptions>searchOptions</searchOptions>
</financialAccountOwnerActivity>
<canChooseAgent>true</canChooseAgent>
</b>
问题: 这里大多数复杂元素为零或更多。我需要循环遍历所有元素。但是如果我们有如上所示的参数很难。我们无法实现每个或任何其他有效的xpath评估,因为在参数中我们有xs:String。有没有办法循环遍历每个元素(或)xsl:param(或)xsl:copy
中的任何有效xpath评估任何帮助表示赞赏
由于 Eresh
答案 0 :(得分:0)
根据我的经验,最简单的方法是:
param.xml
)。<xsl:param name="paramfile" select="'param.xml'"/>
)。document($paramfile)
的变量。如果您从其他一些环境(例如通过Java调用)调用XSLT,可能会有将文档节点或元素节点作为参数传递给XSLT处理器的机制,但细节必须是特定于实现的(判断)通过关于SO的问题往往容易出错。
答案 1 :(得分:0)
我正在上传mule代码以及xslt,我将参数作为文档
发送XSLT文件
<xsl:template match="/">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser="http://service.moneytransfermanagement.financials.icp.sf/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>
<xsl:copy-of select="$xmlObj/node()"/>
<!--
<xsl:copy-of select="//$xmlObj/errorCode"/>
-->
</faultcode>
<faultstring>
</faultstring>
<detail>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
和骡子代码:
<mule-xml:xslt-transformer
xsl-file="xsl/MoneyTransferManagement/ErrorTransformerXMLTest.xsl">
<mule-xml:context-property key="xmlObj"
value="#[groovy:serviceResponse.getFirstChild()]" />
</mule-xml:xslt-transformer>
xml-to-dom-transformer将String转换为DOM,我们可以指定返回类 第一个孩子会给我们元素句柄,同样我们传递给XSL