Gururaj Shivananda
Gururaj Shivananda

Reputation: 11

java external function call saxon 9.9he xslt

we are using xalan for xml transformation. now we are migrating to saxon 9.9 HE for xslt 3.0 support and improved performance.

Current code

Java code

  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-->

i am getting below error for line involving map:get($propsMap,translate($udpname,$lowercase,$uppercase)). i believe 9.9 HE doesnt not support external call functions. alternatively we need to use custom functions using ExtensionFunctionDefinition. not able to figure out how to do the same for reading a map and setting value

Request to suggest how handle map params in xslt in SAxon 9.9 HE

Error stack trace

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)

Upvotes: 0

Views: 1112

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167561

I would suggest to use an XDM 3.1 map (i.e. sequence type map(xs:string, xs:string)) on the XSLT side for the parameter, then you can simply use the XPath 3.1 map access features (e.g. $map($key), $map?key) and XPath 3.1 map functions https://www.w3.org/TR/xpath-functions/#map-functions.

To convert your java.util.Map to an XDM map when you pass in the parameter use the method makeMap (http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XdmMap.html#makeMap-java.util.Map-).

Upvotes: 1

Related Questions