all groups > dotnet xml > november 2004 >
You're in the

dotnet xml

group:

HELP! XSLTranform and XMLTextWriter Error



HELP! XSLTranform and XMLTextWriter Error devanoy NO[at]SPAM hotmail.com
11/29/2004 3:27:27 PM
dotnet xml: I have tried everything with this!

I get an error stating "Index was outside the bounds of the array"

My code looks like this....

xmlDoc = New XmlDocument()
xmlDoc.Load("xml.doc")

xslDoc = New XslTransform()
xslDoc.Load("xsl.doc")

Dim TWrtr As New XmlTextWriter("c:\somelocation.doc",
System.Text.Encoding.UTF8)

xslDoc.Transform(xmlDoc, Nothing, TWrtr)
TWrtr.Close()
xmlDoc = Nothing
xslDoc = Nothing

i do not want to post the XSL/XML as it has customer data in it and it
is extremely long.

I have tried other XSL/XML with this code and it works just fine.

The XSl and XML is under 2 GBs so I know that is not the problem.

If anyone has any solutions to this, please let me know.

Re: HELP! XSLTranform and XMLTextWriter Error pete
11/30/2004 1:10:23 AM
I can't see anything wrong with your code, although it would be more
effcient to use the XPathDocument class in place of the XmlDoxument. This
suggests that there is something wrong with the Xml / Xsl file.

Have you tried performing the same Xml / Xsl translation using XmlSpy (or
other) application?

Pete

[quoted text, click to view]

Re: HELP! XSLTranform and XMLTextWriter Error devanoy NO[at]SPAM hotmail.com
11/30/2004 7:47:18 AM
I am able to do an xml/xsl translation through XML Spy. I DID have to
change the settings of XML Spy to Microsoft XML Parser and v 3.0.

I thought that might be the issue, but I was able to Load everything
in VB.net. I just can't do the XSL Transform. It may still be the
issue, but I am not that experienced in XSL/XML to know how to test if
that is the issue or not.

Any help is greatly appreciated with this! Thanks.

Below is just the top layer of my XSL.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">

<xsl:output indent="yes" method="html" doctype-public="-//W3C//DTD
XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

Re: HELP! XSLTranform and XMLTextWriter Error Wole Ogunremi
11/30/2004 8:28:08 AM
I would guess you've got some faulty xpath inside your xsl. It is worth
downloading a good xpath tester eg Nauman Leghari's
http://www.axisebusiness.com/nleghari/visualxpath.zip


[quoted text, click to view]

Re: HELP! XSLTranform and XMLTextWriter Error Oleg Tkachenko [MVP]
11/30/2004 1:55:28 PM
[quoted text, click to view]

I remember there was some bug in XslTransform with such symptom. Upgrade
to the latest .NET and try to minimize your stylesheet so we can get
some repro.

--
Oleg Tkachenko [XML MVP]
Re: HELP! XSLTranform and XMLTextWriter Error Oleg Tkachenko [MVP]
12/1/2004 12:02:25 PM
[quoted text, click to view]

Well, can you at least provide full exception info including stack trace?

--
Oleg Tkachenko [XML MVP]
Re: HELP! XSLTranform and XMLTextWriter Error devanoy NO[at]SPAM hotmail.com
12/2/2004 9:37:05 AM
I actually figured out the problem for the most part.

The XSL had JavaScripts in it which XMLTextWriter could not handle

Now I am using

Dim xmlDoc As New MSXML2.DOMDocument()
Dim xslProc As MSXML2.IXSLProcessor
Dim xslTemp As MSXML2.XSLTemplate
Dim Doc As New MSXML2.FreeThreadedDOMDocument()
Dim fso As Scripting.FileSystemObject

fso = New Scripting.FileSystemObject()

xmlDoc = New MSXML2.DOMDocument()
xslTemp = New MSXML2.XSLTemplate()
doc = New MSXML2.FreeThreadedDOMDocument()

doc.async = False
Doc.load(("xsl.doc")
xslTemp.stylesheet = doc
xmlDoc.load("xml.doc")
xslProc = xslTemp.createProcessor
xslProc.input = xmlDoc
xslProc.transform()

file = fso.CreateTextFile(c:\somelocation.htm", True)

file.writeline(CStr(xslProc.output))

The only problem with this is that I want to be able to create many
different document types - PDF, DOC, TXT, and HTML. With the file
scripting object I can't do this, can you think of a better solution.
Or can TextWriter handle JavaScripts?
Re: HELP! XSLTranform and XMLTextWriter Error Oleg Tkachenko [MVP]
12/6/2004 11:40:32 AM
[quoted text, click to view]

TextWriter has nothing to do with JavaScript, it's just a writer that
can write a sequential series of characters.

--
Oleg Tkachenko [XML MVP]
Re: HELP! XSLTranform and XMLTextWriter Error Wan Yussman
1/11/2005 9:28:17 PM


I've got the same problem:

Here's the XML file:

------------------------------------------------

<query>
<selectSet>
<select visible="N">
<columnName>arpr_field_oid</columnName>
<columnAlias>result_key</columnAlias>
<indexName>ARPR_FIELD281390</indexName>
<resourceOid>0</resourceOid>
</select>
<select visible="Y">
<columnName>arpr_field_name</columnName>
<columnAlias>field_name</columnAlias>
<indexName>ARPR_FIELD281390</indexName>
<resourceOid>2000910</resourceOid>
</select>
<select visible="Y">
<columnName>d_arpr_main_field_name</columnName>
<columnAlias>main_field_name</columnAlias>
<indexName>ARPR_FIELD281390</indexName>
<resourceOid>2001005</resourceOid>
</select>
<select visible="Y" translate="Y">
<columnName>arpr_field_type_cd</columnName>
<columnAlias>arpr_field_type_cd</columnAlias>
<indexName>ARPR_FIELD281390</indexName>
<resourceOid>2001032</resourceOid>
</select>
</selectSet>
<sortSet>
<sort>
<columnName>main_field_name</columnName>
</sort>
<sort>
<columnName>arpr_field_type_cd</columnName>
</sort>
<sort>
<columnName>field_name</columnName>
</sort>
<sort>
<columnName>result_key</columnName>
</sort>
</sortSet>
<fromSet>
<from>
<tableName>arpr_field</tableName>
<indexName>ARPR_FIELD281390</indexName>
<alias>a</alias>
</from>
</fromSet>
<whereSet>
<where>
<indexFrom>ARPR_FIELD281390</indexFrom>
<columnFrom>deleted_flag</columnFrom>
<operator>=</operator>
<value>N</value>
<dataType>Character</dataType>
</where>
<where upper="Y" wildcard="Y">
<indexFrom>ARPR_FIELD281390</indexFrom>
<columnFrom>arpr_field_name</columnFrom>
<operator>=</operator>
<value>gg</value>
<dataType>Varchar2</dataType>
</where>
</whereSet>
</query>

------------------------------------------------

Here's the XSLT file:

------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v2004 rel. 2 U (http://www.xmlspy.com) by hairul
(iPerintis Sdn Bhd) -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:search="IPSearch">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"
omit-xml-declaration="yes"/>
<xsl:key name="from_indexname" match="/query/fromSet/from"
use="./indexName"/>
<xsl:param name="inWildcard">*</xsl:param>
<xsl:param name="outWildcard">%</xsl:param>
<xsl:param name="hint"/>
<xsl:template match="/">
<xsl:apply-templates select="./query"/>
</xsl:template>
<xsl:template match="query">
<xsl:apply-templates select="./selectSet"/>
<xsl:apply-templates select="./whereSet" mode="from"/>
<xsl:apply-templates select="./whereSet"/>
</xsl:template>
<xsl:template match="selectSet">
<xsl:value-of select="'SELECT '"/>
<xsl:value-of select="concat($hint,' ')"/>
<xsl:apply-templates select="./select"/>
</xsl:template>
<xsl:template match="select">
<xsl:variable name="alias">
<xsl:choose>
<xsl:when test="./columnAlias != ''">
<xsl:value-of select="concat(' AS ',./columnAlias)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="''"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="./functionName">
<xsl:value-of select="concat(./functionName, ' (')"/>
<xsl:apply-templates select="./functionParamSet"/>
<xsl:value-of select="concat(')', $alias)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(key('from_indexname',
./indexName)/alias, '.', ./columnName, $alias)"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="position() != last()">
<xsl:value-of select="','"/>
</xsl:if>
<xsl:value-of select="' '"/>
</xsl:template>
<xsl:template match="functionParamSet">
<xsl:apply-templates select="./functionParam"/>
</xsl:template>
<xsl:template match="functionParam">
<xsl:variable name="quote">
<xsl:choose>
<xsl:when test="./dataType != 'Integer'">
<xsl:value-of select='"&apos;"'/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="''"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="./indexName">
<xsl:value-of select="concat(key('from_indexname',
./indexName)/alias, '.', ./columnName)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($quote, ./value, $quote)"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="position() != last()">
<xsl:value-of select="', '"/>
</xsl:if>
</xsl:template>
<xsl:template match="whereSet" mode="from">
<xsl:choose>
<xsl:when test="count(./where) > 0">
<xsl:choose>
<xsl:when test="count(./where[./indexTo]) > 0">
<xsl:value-of select="'FROM '"/>
<xsl:apply-templates select="./where[./indexTo]" mode="from1"/>
<xsl:apply-templates select="./where[./indexTo]" mode="from2"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('FROM ',key('from_indexname',
./where/indexFrom)/tableName, ' ' ,key('from_indexname',
./where/indexFrom)/alias,' ')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="where" mode="from1">
<xsl:value-of select="'('"/>
</xsl:template>
<xsl:template match="where" mode="from2">
<xsl:variable name="tmp_value1">
<xsl:if test="position() = 1">
<xsl:value-of select="concat(key('from_indexname',
./indexFrom)/tableName, ' ' ,key('from_indexname', ./indexFrom)/alias,'
')"/>
</xsl:if>
</xsl:variable>
<xsl:variable name="tmp_value2">
<xsl:call-template name="wherex">
<xsl:with-param name="indexFrom">
<xsl:value-of select="./indexFrom"/>
</xsl:with-param>
<xsl:with-param name="columnFrom">
<xsl:value-of select="./columnFrom"/>
</xsl:with-param>
<xsl:with-param name="outerjoin">
<xsl:value-of select="./@outerjoin"/>
</xsl:with-param>
<xsl:with-param name="indexTo">
<xsl:value-of select="./indexTo"/>
</xsl:with-param>
<xsl:with-param name="columnTo">
<xsl:value-of select="./columnTo"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat($tmp_value1,' ',$tmp_value2,') ')"/>
</xsl:template>
<xsl:template name="wherex">
<xsl:param name="indexFrom"/>
<xsl:param name="indexTo"/>
<xsl:param name="columnFrom"/>
<xsl:param name="columnTo"/>
<xsl:param name="outerjoin"/>
<xsl:choose>
<xsl:when test="$outerjoin = 'Y'">
<xsl:value-of select="' LEFT JOIN '"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="' JOIN '"/>
</xsl:otherwise>
</xsl:choose>
Re: HELP! XSLTranform and XMLTextWriter Error Oleg Tkachenko [MVP]
1/12/2005 1:49:05 PM
[quoted text, click to view]


[quoted text, click to view]

You know, it's quite big stylesheet. Why don't you tell us what exactly
doesn't seem to be working as you expect?

--
Oleg Tkachenko [XML MVP, MCP]
Re: HELP! XSLTranform and XMLTextWriter Error Elmer Carías
1/12/2005 7:01:12 PM
Hi, i transform your XML with the XSL and no have any problems.
Look your application, but in my application runs and the result was:

SELECT .arpr_field_oid AS result_key, .arpr_field_name AS field_name,
..d_arpr_main_field_name AS main_field_name, .arpr_field_type_cd AS
arpr_field_type_cd FROM WHERE .deleted_flag = 'N' AND
UPPER(.arpr_field_name) = UPPER('gg')



Elmer Carías
El Salvador, CA
MSN: elmer_carias@hotmail.com



[quoted text, click to view]
Re: HELP! XSLTranform and XMLTextWriter Error Wan Yussman
1/13/2005 8:16:23 AM
Well, it doesn't run at all and returns me with "Index was outside the
bounds of the array" error.

I did further tracing and figured that the error comes from this line of
code:

<xsl:when test="count(./where[./indexTo]) > 0">

and this line too:

<xsl:value-of select="concat('FROM ',key('from_indexname',
./where/indexFrom)/tableName, ' ' ,key('from_indexname',
./where/indexFrom)/alias,' ')"/>

It seems that when the indexTo column doesn't exist (because it's
empty), the XSLTransform object returns the above error. The error
doesn't occur when the indexTo column exists, nor does it occur when I
use MSXML2 to do the transformation.

However if I were to reverse / switch conditions and use this line of
code:

<xsl:when test="count(./where[./indexTo]) = 0">

I don't have a problem.

So I'm beginning to think that the XSLTransform has a bug when it's
trying to do a count on a node that doesn't exist.

Wan Yussman

*** Sent via Developersdex http://www.developersdex.com ***
Re: HELP! XSLTranform and XMLTextWriter Error Wan Yussman
1/13/2005 8:31:22 AM
Hi Elmer,

I assumed that you did a cut and paste of the result, so that SQL would
never work if you ran it in any database. The FROM clause is empty.

Are you sure you ran the code in .NET v1.1 and not XMLSpy or using
MSXML2?

Because I tested it in 6 different types of servers here, all installed
with .NET v1.1, and they all produced the same error.

The funny thing is that when I used XMLSpy there's no problem, and same
with MSXML2.

In my response to Oleg, I figured out the line of code that caused the
error. Had to fix it using a workaround which is not a comfortable
thought. Problem is fixed temporarily, but I am wondering if it's my
environment/IDE/.NET installation or if there's definitely a small
problem with the XSLTransform object, which is why I'm looking if anyone
else can reproduce this error to determine which of the above is true.

Wan Yussman

*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button