I'm rewriting some XSLT 2.0 templates to make them XSLT 1.0 compatible (Xalan processor). We are using iterations through collections got from java call. But if I try to iterate these collections using for-each and Xalan I am getting
Can not convert #UNKNOWN (java.util.LinkedHashMap) to NodeList!
Is there any way how to do this or is this XSLT 2.0 only? In other words: do I need to convert all collections to NodeSets on my own? Seems that nodeset extension is not the case because it converts the collection to one item nodeset containing all items of original collection.
EDIT:
Formerly we're using Saxon, please see template fragment
<xsl:variable name="profilesTable" select="javaEagle:getAllProfileInfo()"/>
<xsl:variable name="profilesList" select="javaEagle:getProfileList()"/>
<xsl:variable name="loopInc" select="0"/>
<xsl:variable name="profileSize" select="set:size($profilesList)"/>
<xsl:if test="map:size($profilesTable) > 0">
<table>
<tgroup cols="{$profileSize}">
<colspec colnum="propertyName" colname="propertyName" colwidth="1*"/>
<xsl:for-each select="$profilesList">
<xsl:variable name="loopInc" select="$loopInc + 1" />
<colspec colnum="{$loopInc}" colname="col{$loopInc}" colwidth="1*"/>
</xsl:for-each>
<thead>
<row>
<entry valign="top">Module Property Name</entry>
<xsl:for-each select="$profilesList">
<entry valign="top"><xsl:value-of select="."/></entry>
</xsl:for-each>
</row>
</thead>
<tbody>
<xsl:for-each select="common:node-set(map:keySet($profilesTable))">
<xsl:variable name="key" select="."/>
<row>
<entry id="{$key}" namest="col1" nameend="col{$profileSize}" align="left"><b><xsl:value-of select="$key"/></b></entry>
<xsl:variable name="properties" select="map:get($profilesTable, string($key))"/>
Problematic part of code is this:
<xsl:for-each select="common:node-set(map:keySet($profilesTable))">
<xsl:variable name="key" select="."/>
... do somenthing with keys
$profilesTable is HashMap returned from java call.
Without common:nodeset extension I am getting error
Can not convert #UNKNOWN (java.util.LinkedHashMap) to NodeList!
With common:nodeset it seems loop goes over the whole nodeset as one item.
So the question is how to iterate through keys of returned hashmap using xalan processor.
EDIT2:
Reduced example:
<xsl:template match='/'>
<xsl:variable name="profilesTable" select="CustomFunctionsEagle:getAllProfileInfo()"/>
<xsl:if test="map:size($profilesTable) > 0">
<table>
<tbody>
<xsl:variable name="keys" select="common:node-set(map:keySet($profilesTable))"/>
<AllKeys><xsl:value-of select="$keys"/></AllKeys>
<xsl:for-each select="$keys/*">
<xsl:for-each select="/">
<GlobalVariable><xsl:value-of select="."/></GlobalVariable>
</xsl:for-each>
</xsl:for-each>
</tbody>
</table>
</xsl:if>
</xsl:template>
Output:
<?xml version="1.0" encoding="utf-8"?>
<table>
<tbody>
<AllKeys>[/AccountState/BW.HOST.NAME, .... another keys]</AllKeys>
</tbody>
</table>
Expected:
<table>
<tbody>
<AllKeys>[/AccountState/BW.HOST.NAME, .... another keys]</AllKeys>
<GlobalVariable>/AccountState/BW.HOST.NAME</GlobalVariable>
<GlobalVariable>... another keys</GlobalVariable>
</tbody>
</table>