IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

AltovaXml: Strange Behavior Options · View
warstar
Posted: Thursday, August 6, 2009 2:25:29 PM
Rank: Newbie

Joined: 8/6/2009
Posts: 4
Location: NL
Hi all,

I'm trying to add a item to a HashTable (using xml and xslt 2.0 and the .net extension). The only problem is that i get errors like "CSharp execution error - 'Error: Exception has been thrown by the target of an invocation.' - hashtable:Add". After some research i found out that if i added a clear call to the variable containing the hash there where no errors any more.

Is there any one who known why this is?

My Xslt looks like:
Code:

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:fn="http://www.w3.org/2005/xpath-functions"
    xmlns:hashtable="clitype:System.Collections.Hashtable">

    <xsl:output method="text" omit-xml-declaration="yes"/>

    <xsl:variable name="languageCode" select="'lang'" />
    
    <xsl:template match="/">
        <xsl:for-each select="nodes/node">
            <xsl:apply-templates select="."></xsl:apply-templates>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="node">
        <xsl:variable name="x" select="'a'" />

        <xsl:variable name="itemAttributes" select="hashtable:new()"/>
        <xsl:value-of select="hashtable:Add( $itemAttributes, 'id', $x )" />
        <xsl:value-of select="hashtable:get_Item($itemAttributes, 'id')" />
        <!-- need the following line to get to errors -->
        <xsl:value-of select="hashtable:Clear($itemAttributes)" />
    </xsl:template>

</xsl:stylesheet>


My Xml looks like:
Code:

<?xml version="1.0" encoding="utf-8" ?>
<nodes>
    <node id="id"></node>
    <node id="id"></node>
</nodes>


Cheers,
Warnar
vlad
Posted: Friday, August 7, 2009 7:25:53 AM
Rank: Advanced Member

Joined: 12/13/2005
Posts: 2,856
Location: Mauritius
Hi warstar,

what do you mean by a "clear call"?
warstar
Posted: Friday, August 7, 2009 7:41:44 AM
Rank: Newbie

Joined: 8/6/2009
Posts: 4
Location: NL
Hi vlad,

What i mean is that looking at the xslt i would expect that every time the "<xsl:template match="node">" is run a new instance of the hashtable would be created.
It seems that i only creates the instance once and that is why every time after finishing the template i need to Clear the hashtable.

This seems illogical to me or do you know if this is excepted behaviour?

(it also seems if i use a "<xsl:element use-attribute-sets" in some cases the information within the "<xsl:attribute-set" get's chached maybe this is the same problem)
vlad
Posted: Friday, August 7, 2009 11:21:23 AM
Rank: Advanced Member

Joined: 12/13/2005
Posts: 2,856
Location: Mauritius
This one seems to be a bug. You workaround is probably the most appropriate one.
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.