gpt4 book ai didi

java外部函数调用saxon 9.9he xslt

转载 作者:行者123 更新时间:2023-12-02 09:11:28 25 4
gpt4 key购买 nike

我们使用xalan进行 xml 转换。现在我们正在迁移到 saxon 9.9 HE 以获取 xslt 3.0 支持并提高性能。

当前代码

Java代码

  HashMap<String, String> columnPropsMap= getProperties(strDSNName);

transformer.setParameter("propsMap", columnPropsMap);//set map to xslt

**XSLT**
...xmlns:map="xalan://java.util.Map" extension-element-prefixes="map"
...<xsl:param name="propsMap"/> <!--read map passed from java-->
...<xsl:variable name="defaultvalue" select="map:get($propsMap,translate($udpname,$lowercase,$uppercase))"/><!-- retrieve the property for udp(property) by udpname from hashmap propsMap-->



**New code**

**java**
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");//set saxon transformer factory

**XSLT**

xmlns:map="http://ns.saxonica.com/map" extension-element-prefixes="map"<!--namespace change-->

涉及 map:get($propsMap,translate($udpname,$lowercase,$uppercase)) 的行出现以下错误。我相信9.9 HE不支持外部通话功能。或者,我们需要使用 ExtensionFunctionDefinition 来使用自定义函数。无法弄清楚如何执行相同的操作来读取 map 和设置值

请求建议如何在 SAxon 9.9 HE 中处理 xslt 中的 map 参数

错误堆栈跟踪

Error evaluating ((element()[fn:name(...) eq "UDP_Instance_Groups"])/element()[fn:name(...) eq "UDP_Instance"]!let $udpval := ...) in xsl:variable/@select on line 953 column 113 
XTDE1425: Cannot find a 2-argument function named Q{http://ns.saxonica.com/map}get()
invoked by unknown caller (class net.sf.saxon.expr.instruct.ForEach) at #947
invoked by unknown caller (class net.sf.saxon.expr.instruct.ForEach) at #568
In template rule with match="*[fn:name(...) eq "Physical_Columns_Order_Ref"]" on line 565 of
invoked by xsl:apply-templates at #509
invoked by unknown caller (class net.sf.saxon.expr.instruct.ForEach) at #81
In template rule with match="/" on line 38 of
; SystemID: ; Line#: 953; Column#: 60
net.sf.saxon.trans.XPathException: Cannot find a 2-argument function named Q{http://ns.saxonica.com/map}get()
at net.sf.saxon.expr.ErrorExpression.evaluateItem(ErrorExpression.java:149)
at net.sf.saxon.expr.parser.Evaluator$5.evaluate(Evaluator.java:191)
at net.sf.saxon.expr.parser.Evaluator$5.evaluate(Evaluator.java:188)
at net.sf.saxon.expr.LetExpression.eval(LetExpression.java:532)
at net.sf.saxon.expr.LetExpression.process(LetExpression.java:601)
at net.sf.saxon.expr.instruct.ForEach.lambda$processLeavingTail$0(ForEach.java:484)
at net.sf.saxon.expr.instruct.ForEach$$Lambda$51/1933790033.accept(Unknown Source)
at net.sf.saxon.om.SequenceIterator.forEachOrFail(SequenceIterator.java:128)
at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:484)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:352)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:299)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:723)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:723)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:723)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:723)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:352)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:299)
at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:723)
at net.sf.saxon.expr.instruct.Choose.processLeavingTail(Choose.java:896)
at net.sf.saxon.expr.instruct.Choose.processLeavingTail(Choose.java:896)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132)
at net.sf.saxon.expr.instruct.ForEach.lambda$processLeavingTail$0(ForEach.java:484)
at net.sf.saxon.expr.instruct.ForEach$$Lambda$51/1933790033.accept(Unknown Source)
at net.sf.saxon.om.SequenceIterator.forEachOrFail(SequenceIterator.java:128)
at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:484)
at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:723)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:352)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:533)
at net.sf.saxon.expr.instruct.ApplyTemplates.apply(ApplyTemplates.java:300)
at net.sf.saxon.expr.instruct.ApplyTemplates.process(ApplyTemplates.java:251)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:352)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:299)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:723)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:352)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:299)
at net.sf.saxon.expr.instruct.Choose.processLeavingTail(Choose.java:896)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132)
at net.sf.saxon.expr.instruct.ForEach.lambda$processLeavingTail$0(ForEach.java:484)
at net.sf.saxon.expr.instruct.ForEach$$Lambda$51/1933790033.accept(Unknown Source)
at net.sf.saxon.om.SequenceIterator.forEachOrFail(SequenceIterator.java:128)
at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:484)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:352)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:299)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:352)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:299)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:352)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:299)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:352)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:299)
at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:723)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:352)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:533)

最佳答案

我建议在 XSLT 端使用 XDM 3.1 映射(即序列类型 map(xs:string, xs:string))作为参数,然后您可以简单地使用 XPath 3.1 map 访问功能(例如 $map($key)$map?key)和 XPath 3.1 map 函数 https://www.w3.org/TR/xpath-functions/#map-functions .

要在传入参数时将 java.util.Map 转换为 XDM 映射,请使用方法 makeMap ( http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XdmMap.html#makeMap-java.util.Map- )。

关于java外部函数调用saxon 9.9he xslt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59391953/

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