Re: [xsl] XslTrasnformation - Index was outside the bounds of the array

Subject: Re: [xsl] XslTrasnformation - Index was outside the bounds of the array
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 08 Jan 2007 12:08:59 +0100
Karl Stubsjoen wrote:
I am getting an Index was outside the bounds of the array error when I
apply the following template select:

Where do you get the IndexOutOfBoundsError? That is not an XSLT error, so it has to do something with your .NET code.



<xsl:apply-templates select="*[name() = $Fields_MappedForUpdate/Field]"/>


I do not get this error if I remove the /Field from above.  This feels
like a big nasty bug to me.

I assume you do something with the returned results, which are apparently not of the form you expect (?)


Can you paste in a snippet of your C#/VB that raises this exception? What is the source/xslt context of the xslt statement above?


$Fields_MappedForUpdate is the result of a node-set creation like this:
<xsl:variable name="Fields_MappedForUpdate" select="fx:node-set($xx_fields)"/>

Most notably, this looks like you have something as follows (but I am guessing now):


<xsl:variable name="Fields_MappedForUpdate" select="fx:node-set($xx_fields)" />
<xsl:variable name="xx_fields">
<Field>Something</Field>
<Field>Something</Field>
.....
</xsl:variable>


Since you have an IOOB error in your .NET code, I assume (guessing again), that the select statement above should produce some output for you and that *with* the "/Field" it does not (like you said). The output must be of a certain form to prevent the IOOB error from occurring (which prompts me to add: some check on the output from the transformation would probably be a good idea).

Still guessing, the most likely cause when nodes suddenly don't match, is a wrong namespace. Since you use a variable, the namespace is the null-namespace (unless the nodes specifically are set with a namespace). If your default namespace differs, you will not have a match. The following example shows this:

<xsl:stylesheet version="1.0"
xmlns = "urn:test"
xmlns:exsl="http://exslt.org/common";
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output indent="yes"/>
<xsl:variable name="data">
<one>This is one</one>
</xsl:variable>
<xsl:template match="/">
<test>
<!-- still inside namespace urn:test, will not match "one" -->
<xsl:apply-templates select="exsl:node-set($data)/one" />
<!-- this will match 'one' -->
<xsl:apply-templates select="exsl:node-set($data)/*[local-name() = 'one']" />
</test>
</xsl:template>
<xsl:template match="one">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>



Not sure this helps, however ;-)


Cheers,
-- Abel Braaksma
  http://www.nuntia.nl

Current Thread