java外部函数调用saxon 9.9he xslt

问题描述 投票:0回答:1

我们正在使用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使用自定义函数。无法弄清楚如何读取地图和设置值

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

错误堆栈跟踪

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)
java xslt saxon
1个回答
1
投票

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

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

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.