Hey Michael,

Apologies for my unclear request for help.

What has escaped me how to construct the XdmValue type for the second parameter from a Map.
ObjectValue can wrap an Object, but is not itself an XdmValue.

        transformer.setParameter(new QName("map"), *** How to create an XdmValue from a Java Map object? ***);

This does seem to do the trick:

        final XdmItem xdmItem = new ItemTypeFactory(processor).getExternalObject(map);
        transformer.setParameter(new QName("map"), xdmItem);

with the minor drawback of requiring keeping the processor about for wrapping parameters, but might be the best possible solution.

thanks very much for your help

Alan PAINTER
Team Colossus | Strategic Components
15, rue Vernet, 75419 Paris, France
_____________________________________________

Phone  +33 (0) 1 40 70 31 19
Mobile +33 (0) 6 75 13 29 29
Email alan.painter@hsbc.fr


_____________________________________________





De :        Michael Kay <mike@saxonica.com>
A :        Mailing list for the SAXON XSLT and XQuery processor <saxon-help@lists.sourceforge.net>
Date :        09/21/2013 12:07 AM
Objet :        Re: [saxon] ghosts of saxon past (saxon 9.1.0.8) Help on the magic        incantation for setParameter(new QName("map"),        ArbitraryJavaObject)  ?




Alan, you didn't finish your sentence where I think you were going to explain what goes wrong.

Memories of 9.1 are fading fast, but I think you should be able to wrap the HashMap in an instance of net.sf.saxon.value.ObjectValue, and pass that as the parameter. I would also have expected you to be able to pass the HashMap directly, but passing instances of Java's collection classes is a bit fragile because Saxon sometimes converts them to an XDM sequence or (in recent releases) an XDM map.

Michael Kay
Saxonica


On 20 Sep 2013, at 06:57, alan.painter@hsbc.fr wrote:

Hi,

In saxon 9.1.0.8 (saxon-B), trying to pull information out of a Java Map.


I'm able to retrieve such a map from a java static method that returns a map, getMap(), as in this stylesheet:


<xsl:stylesheet version="2.0"

               xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"

               xmlns:class="
http://saxon.sf.net/java-type"
               xmlns:map="java:java.util.Map"

               xmlns:mapGetter="java:MyPacakge.MapGetter"


               exclude-result-prefixes="xsl class map mapGetter">


   <xsl:param name="map" as="class:java.util.Map" required="no" select="mapGetter:getMap()"/>


   <xsl:output method="xml" indent="yes"/>


   <xsl:template name="writeMapContents">

       <map>

           <xsl:for-each select="map:keySet($map)">

               <mapEntry key="{.}" value="{map:get($map, .)}"/>

           </xsl:for-each>

       </map>

   </xsl:template>


</xsl:stylesheet>


However, when I want to remove the default value from the stylesheet parameter and pass the map as a parameter, as in:


   <xsl:param name="map" as="class:java.util.Map" required="yes" />


with this java code


public static void main(String args[]) throws IOException, SaxonApiException {

       final Processor processor = new Processor(false);

       final XsltCompiler compiler = processor.newXsltCompiler();

       final XsltExecutable compiledXslt = compiler.compile(new StreamSource("ReturnsMapContents.xslt"));


       final XsltTransformer transformer = compiledXslt.load();


       final Serializer serializer = new Serializer();

       serializer.setOutputStream(System.out);

       transformer.setDestination(serializer);


       final Map<String, String> map = new HashMap<String, String>();

       map.put("keyOne",   "valueOne");

       map.put("keyTwo",   "valueTwo");

       map.put("keyThree", "valueThree");


       transformer.setParameter(new QName("map"), *** How to create an XdmValue from a Java Map object? ***);

       transformer.setInitialTemplate(new QName("writeMapContents"));

       transformer.transform();


}


Thanks for any help and apologies for using an old version (with the feeble disclaimer that it is tried and true)


-alan

Ensemble adoptons des gestes responsables : N'imprimez ce mail que si necessaire. Les informations contenues dans ce message et les pieces jointes (ci-apres denomme le message) sont confidentielles et peuvent etre couvertes par le secret professionnel. Si vous n'etes pas le destinataire de ce message, il vous est interdit de le copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. Si vous avez recu ce message par erreur, nous vous remercions de le supprimer de votre systeme, ainsi que toutes ses copies, et d'en avertir immediatement HSBC France et ses filiales par message de retour. Il est impossible de garantir que les communications par messagerie electronique arrivent en temps utile, sont securisees ou denuees de toute erreur, alteration, falsification ou virus. En consequence, HSBC France et ses filiales declinent toute responsabilite du fait des erreurs, alterations, falsifications ou omissions qui pourraient en resulter. Consider the environment before printing this mail. The information contained in this e-mail is confidential. It may also be legally privileged. If you are not the addressee you may not copy, forward, disclose or use any part of it. If you have received this message by error, please delete it and all copies from your system and notify the sender immediately by return e-mail. E-mail communications cannot be guaranteed to be timely secure, error or virus-free. The sender does not accept liability for any errors or omissions which arise as a result.------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13.

http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk_______________________________________________
saxon-help mailing list archived at
http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help
------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13.
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk

_______________________________________________
saxon-help mailing list archived at
http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help