Mateusz,

Thanks for the recommendation.  

I do agree that XSLT3.0 and Saxon-EE have a lot of value to add for the XSLT developer and for runtime optimization.
I also agree that it would be possible to split up a Map into two lists.
One could also write the contents of the map to XML and include it as a document.
The possibilities are probably endless.

But what I'm really curious about is how to pass a Java Map parameter to the stylesheet from the s9api.

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

This is more of a case of trying to fill in a gaping hole in my understanding of the saxon toolset.

thanks all the same and cheers

-alan




De :        "Nowakowski, Mateusz" <Mateusz.Nowakowski@sabre.com>
A :        Mailing list for the SAXON XSLT and XQuery processor <saxon-help@lists.sourceforge.net>
Date :        09/20/2013 10:13 AM
Objet :        Re: [saxon] ghosts of saxon past (saxon 9.1.0.8) Help on the magic incantation for setParameter(new QName("map"), ArbitraryJavaObject)  ?




Well recently I wanted to do the same, but I use saxon-he 9.5 where some features are not present comparing to 9.1. ( they are present in PE/EE versions in http://saxonica.com/documentation/html/extensibility/ but  yeah…nobody wants to pay).
 
However there is a workaround which will also work in 9.1
 
Convert a map to two list: keys and values (use LinkedHashMap to maintain correct order)
Here is a snippet from my last transformation:
 
 
    <xsl:param name="headersNames" select="()"/>
    <xsl:param name="headersValues" select="()"/>
 
    <xsl:template match="/">
        <xsl:element name="soap-env:Envelope" namespace="http://schemas.xmlsoap.org/soap/envelope/">
            <xsl:element name="soap-env:Header">
                <xsl:namespace name="eh" select="'http://someNamespace'"/>
                <xsl:for-each select="$headersNames">
                    <xsl:element name="eh:{.}" inherit-namespaces="yes">
                        <xsl:variable name="pos" select="fn:position()"/>
                        <xsl:value-of select="$headersValues[fn:position() = $pos]"/>
                    </xsl:element>
                </xsl:for-each>
            </xsl:element>
            <xsl:element name="soap-env:Body">
                <xsl:copy-of select="*" copy-namespaces="no"/>
            </xsl:element>
        </xsl:element>
    </xsl:template>
 
Hope it helps.
 
PS. You can always upgrade and   pay and use promising xslt 3.0 features like map.
Or write custom http://saxonica.com/documentation/html/extensibility/integratedfunctions/
which is still for free.
 
--
Regards,
Mateusz Nowakowski
 
From: alan.painter@hsbc.fr [mailto:alan.painter@hsbc.fr]
Sent:
20 września 2013 07:57
To:
saxon-help@lists.sourceforge.net
Subject:
[saxon] ghosts of saxon past (saxon 9.1.0.8) Help on the magic incantation for setParameter(new QName("map"), ArbitraryJavaObject) ?

 
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