473,378 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

HELP! XSLTranform and XMLTextWriter Error

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.

Thanks,
Nov 12 '05 #1
12 2107
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

"Amanda" <de*****@hotmail.com> wrote in message
news:55**************************@posting.google.c om...
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.

Thanks,

Nov 12 '05 #2
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
"Amanda" <de*****@hotmail.com> wrote in message
news:55**************************@posting.google.c om...
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.

Thanks,

Nov 12 '05 #3
Amanda wrote:
I get an error stating "Index was outside the bounds of the array"


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]
http://blog.tkachenko.com
Nov 12 '05 #4
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"/>

</xsl:stylesheet>
Nov 12 '05 #5
Amanda wrote:
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.


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

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #6
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?

Nov 12 '05 #7
de*****@hotmail.com wrote:
Or can TextWriter handle JavaScripts?


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

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #8


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>
<xsl:value-of select="concat(key('from_indexname',
$indexTo)/tableName, ' ' ,key('from_indexname', $indexTo)/alias,' ON
')"/>
<xsl:value-of select="concat(key('from_indexname',
$indexFrom)/alias,'.',$columnFrom,' ',./operator,'
',key('from_indexname', $indexTo)/alias,'.',$columnTo)"/>
</xsl:template>
<xsl:template match="whereSet">
<xsl:choose>
<xsl:when test="count(./where[not(./indexTo)]) > 0">
<xsl:value-of select="'WHERE '"/>
<xsl:apply-templates select="./where[not(./indexTo)]"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="where">
<xsl:choose>
<xsl:when test="./operator = 'IS NULL' or ./operator = 'IS NOT
NULL'">
<xsl:value-of select="concat(key('from_indexname',
../indexFrom)/alias, '.', ./columnFrom, ' ',./operator, ' ')"/>
</xsl:when>
<xsl:when test="./value">
<xsl:variable name="tmp_value">
<xsl:call-template name="replace-substring">
<xsl:with-param name="text">
<xsl:value-of select="./value"/>
</xsl:with-param>
<xsl:with-param name="from">&amp;apos;</xsl:with-param>
<xsl:with-param name="to">'</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="value">
<xsl:choose>
<xsl:when test="./dataType='Integer'">
<xsl:value-of select="$tmp_value"/>
</xsl:when>
<xsl:when test='substring(./value, 1, 1)="&apos;"'>
<xsl:value-of select="$tmp_value"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='concat("&apos;", $tmp_value, "&apos;")'/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="./@truncate = 'Y'">
<xsl:value-of
select="concat('CONVERT(datetime,CONVERT(varchar(2 0),',
key('from_indexname', ./indexFrom)/alias, '.', ./columnFrom, ', 106))
',./operator, ' ', $value)"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkUpper">
<xsl:with-param name="left" select="concat(key('from_indexname',
../indexFrom)/alias, '.', ./columnFrom, ' ')"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="operator" select="./operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkOuterJoin">
<xsl:with-param name="left" select="concat(key('from_indexname',
../indexFrom)/alias, '.', ./columnFrom, ' ')"/>
<xsl:with-param name="value" select="concat(key('from_indexname',
../indexTo)/alias, '.', ./columnTo)"/>
<xsl:with-param name="operator" select="./operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="position() != last()">
<xsl:value-of select="' AND'"/>
</xsl:if>
<xsl:value-of select="' '"/>
</xsl:template>
<xsl:template name="checkUpper">
<xsl:param name="left"/>
<xsl:param name="value"/>
<xsl:param name="operator"/>
<xsl:choose>
<xsl:when test="./@upper = 'Y'">
<xsl:call-template name="checkGroup">
<xsl:with-param name="left" select="concat('UPPER(',
normalize-space($left), ') ')"/>
<xsl:with-param name="value">
<xsl:call-template name="upper-case">
<xsl:with-param name="text" select="$value"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkGroup">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="string($value)"/>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="checkGroup">
<xsl:param name="left"/>
<xsl:param name="value"/>
<xsl:param name="operator"/>
<xsl:choose>
<xsl:when test="./@group = 'Y' and $operator = '='">
<xsl:call-template name="checkWildcard">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="concat('(',
search:ConvertGroup($value), ')')"/>
<xsl:with-param name="operator" select="'IN'"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="./@group = 'Y' and $operator != '='">
<xsl:call-template name="checkWildcard">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="concat('',
search:ConvertGroup($value), '')"/>
<xsl:with-param name="operator" select="'NOT IN'"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkWildcard">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="checkWildcard">
<xsl:param name="left"/>
<xsl:param name="value"/>
<xsl:param name="operator"/>
<xsl:choose>
<xsl:when test="./@wildcard = 'Y' and contains($value, $inWildcard)">
<xsl:call-template name="checkOuterJoin">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="translate($value, $inWildcard,
$outWildcard)"/>
<xsl:with-param name="operator">
<xsl:choose>
<xsl:when test="$operator = '='">LIKE</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$operator"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkOuterJoin">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="checkOuterJoin">
<xsl:param name="left"/>
<xsl:param name="value"/>
<xsl:param name="operator"/>
<xsl:choose>
<xsl:when test="./@outerjoin = 'Y'">
<xsl:call-template name="checkOperator">
<xsl:with-param name="left"
select="concat('ISNULL(',$left,',',$value,')')"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkOperator">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="checkOperator">
<xsl:param name="left"/>
<xsl:param name="value"/>
<xsl:param name="operator"/>
<xsl:choose>
<xsl:when test="./operator = 'IN' or ./operator = 'NOT IN'">
<xsl:value-of select="concat(' ', $left, $operator, ' (', $value,
')')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(' ', $left, $operator, ' ', $value)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="upper-case">
<xsl:param name="text"/>
<xsl:value-of select="concat('UPPER(', $text, ')')"/>
</xsl:template>
<xsl:template name="replace-substring">
<xsl:param name="text"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:choose>
<xsl:when test="contains($text,$from)">
<xsl:value-of select="substring-before($text, $from)"/>
<xsl:copy-of select="$to"/>
<xsl:call-template name="replace-substring">
<xsl:with-param name="text" select="substring-after($text,$from)"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

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

Here's the code:

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

Private Function BuildSQL() As String
Const THIS_ROUTINE As String = "BuildSQL"

Dim objQuery As New XmlDocument
Dim objXSL As New Xsl.XslTransform
Dim swTemp As New IO.StringWriter
Dim objXMLNav As XPath.XPathNavigator
Dim objXSLArgList As New Xsl.XsltArgumentList
Dim szXSLFile As String

'LogTrace(IPLogLevel.IPLogLevelLow, m_szSessionID,
THIS_SUBSYSTEM, THIS_CLASS, THIS_ROUTINE, "Entry")

BuildSQL = ""

Try
objQuery.Load("XMLFile.xml")

objXMLNav = objQuery.CreateNavigator
objXSL.Load("XSLTFile.xsl")

objXSLArgList.AddExtensionObject("IPSearch", Me)
objXSL.Transform(objXMLNav, objXSLArgList, swTemp, Nothing)

BuildSQL = swTemp.ToString()
Catch
With Err()
.Raise(.Number, .Source, .Description)
End With
End Try

'LogTrace(IPLogLevel.IPLogLevelLow, m_szSessionID,
THIS_SUBSYSTEM, THIS_CLASS, THIS_ROUTINE, "Exit")
End Function

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

I'm using .NET v1.1.

It will work in XMLSpy but not when with XSLTransform.

An MS bug?

Wan Yussman

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #9
Wan Yussman wrote:

It will work in XMLSpy but not when with XSLTransform.

An MS bug?


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]
http://blog.tkachenko.com
Nov 12 '05 #10
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: el**********@hotmail.com

"Wan Yussman" <yu*****@hotmail.com> wrote in message
news:u0****************@TK2MSFTNGP09.phx.gbl...


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>
<xsl:value-of select="concat(key('from_indexname',
$indexTo)/tableName, ' ' ,key('from_indexname', $indexTo)/alias,' ON
')"/>
<xsl:value-of select="concat(key('from_indexname',
$indexFrom)/alias,'.',$columnFrom,' ',./operator,'
',key('from_indexname', $indexTo)/alias,'.',$columnTo)"/>
</xsl:template>
<xsl:template match="whereSet">
<xsl:choose>
<xsl:when test="count(./where[not(./indexTo)]) > 0">
<xsl:value-of select="'WHERE '"/>
<xsl:apply-templates select="./where[not(./indexTo)]"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="where">
<xsl:choose>
<xsl:when test="./operator = 'IS NULL' or ./operator = 'IS NOT
NULL'">
<xsl:value-of select="concat(key('from_indexname',
/indexFrom)/alias, '.', ./columnFrom, ' ',./operator, ' ')"/>
</xsl:when>
<xsl:when test="./value">
<xsl:variable name="tmp_value">
<xsl:call-template name="replace-substring">
<xsl:with-param name="text">
<xsl:value-of select="./value"/>
</xsl:with-param>
<xsl:with-param name="from">&amp;apos;</xsl:with-param>
<xsl:with-param name="to">'</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="value">
<xsl:choose>
<xsl:when test="./dataType='Integer'">
<xsl:value-of select="$tmp_value"/>
</xsl:when>
<xsl:when test='substring(./value, 1, 1)="&apos;"'>
<xsl:value-of select="$tmp_value"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='concat("&apos;", $tmp_value, "&apos;")'/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="./@truncate = 'Y'">
<xsl:value-of
select="concat('CONVERT(datetime,CONVERT(varchar(2 0),',
key('from_indexname', ./indexFrom)/alias, '.', ./columnFrom, ', 106))
',./operator, ' ', $value)"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkUpper">
<xsl:with-param name="left" select="concat(key('from_indexname',
/indexFrom)/alias, '.', ./columnFrom, ' ')"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="operator" select="./operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkOuterJoin">
<xsl:with-param name="left" select="concat(key('from_indexname',
/indexFrom)/alias, '.', ./columnFrom, ' ')"/>
<xsl:with-param name="value" select="concat(key('from_indexname',
/indexTo)/alias, '.', ./columnTo)"/>
<xsl:with-param name="operator" select="./operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="position() != last()">
<xsl:value-of select="' AND'"/>
</xsl:if>
<xsl:value-of select="' '"/>
</xsl:template>
<xsl:template name="checkUpper">
<xsl:param name="left"/>
<xsl:param name="value"/>
<xsl:param name="operator"/>
<xsl:choose>
<xsl:when test="./@upper = 'Y'">
<xsl:call-template name="checkGroup">
<xsl:with-param name="left" select="concat('UPPER(',
normalize-space($left), ') ')"/>
<xsl:with-param name="value">
<xsl:call-template name="upper-case">
<xsl:with-param name="text" select="$value"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkGroup">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="string($value)"/>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="checkGroup">
<xsl:param name="left"/>
<xsl:param name="value"/>
<xsl:param name="operator"/>
<xsl:choose>
<xsl:when test="./@group = 'Y' and $operator = '='">
<xsl:call-template name="checkWildcard">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="concat('(',
search:ConvertGroup($value), ')')"/>
<xsl:with-param name="operator" select="'IN'"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="./@group = 'Y' and $operator != '='">
<xsl:call-template name="checkWildcard">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="concat('',
search:ConvertGroup($value), '')"/>
<xsl:with-param name="operator" select="'NOT IN'"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkWildcard">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="checkWildcard">
<xsl:param name="left"/>
<xsl:param name="value"/>
<xsl:param name="operator"/>
<xsl:choose>
<xsl:when test="./@wildcard = 'Y' and contains($value, $inWildcard)">
<xsl:call-template name="checkOuterJoin">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="translate($value, $inWildcard,
$outWildcard)"/>
<xsl:with-param name="operator">
<xsl:choose>
<xsl:when test="$operator = '='">LIKE</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$operator"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkOuterJoin">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="checkOuterJoin">
<xsl:param name="left"/>
<xsl:param name="value"/>
<xsl:param name="operator"/>
<xsl:choose>
<xsl:when test="./@outerjoin = 'Y'">
<xsl:call-template name="checkOperator">
<xsl:with-param name="left"
select="concat('ISNULL(',$left,',',$value,')')"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkOperator">
<xsl:with-param name="left" select="$left"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="operator" select="$operator"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="checkOperator">
<xsl:param name="left"/>
<xsl:param name="value"/>
<xsl:param name="operator"/>
<xsl:choose>
<xsl:when test="./operator = 'IN' or ./operator = 'NOT IN'">
<xsl:value-of select="concat(' ', $left, $operator, ' (', $value,
')')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(' ', $left, $operator, ' ', $value)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="upper-case">
<xsl:param name="text"/>
<xsl:value-of select="concat('UPPER(', $text, ')')"/>
</xsl:template>
<xsl:template name="replace-substring">
<xsl:param name="text"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:choose>
<xsl:when test="contains($text,$from)">
<xsl:value-of select="substring-before($text, $from)"/>
<xsl:copy-of select="$to"/>
<xsl:call-template name="replace-substring">
<xsl:with-param name="text" select="substring-after($text,$from)"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

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

Here's the code:

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

Private Function BuildSQL() As String
Const THIS_ROUTINE As String = "BuildSQL"

Dim objQuery As New XmlDocument
Dim objXSL As New Xsl.XslTransform
Dim swTemp As New IO.StringWriter
Dim objXMLNav As XPath.XPathNavigator
Dim objXSLArgList As New Xsl.XsltArgumentList
Dim szXSLFile As String

'LogTrace(IPLogLevel.IPLogLevelLow, m_szSessionID,
THIS_SUBSYSTEM, THIS_CLASS, THIS_ROUTINE, "Entry")

BuildSQL = ""

Try
objQuery.Load("XMLFile.xml")

objXMLNav = objQuery.CreateNavigator
objXSL.Load("XSLTFile.xsl")

objXSLArgList.AddExtensionObject("IPSearch", Me)
objXSL.Transform(objXMLNav, objXSLArgList, swTemp, Nothing)

BuildSQL = swTemp.ToString()
Catch
With Err()
.Raise(.Number, .Source, .Description)
End With
End Try

'LogTrace(IPLogLevel.IPLogLevelLow, m_szSessionID,
THIS_SUBSYSTEM, THIS_CLASS, THIS_ROUTINE, "Exit")
End Function

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

I'm using .NET v1.1.

It will work in XMLSpy but not when with XSLTransform.

An MS bug?

Wan Yussman

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Nov 12 '05 #11
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 ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #12
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 ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
2
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.