473,396 Members | 1,898 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,396 software developers and data experts.

How to rewrite Dynamic XPath jscript evaluate in c#

I have no problems running the following dynamic XPath evaluator form MSXSL:

<msxsl:script implements-prefix="dyn" language="jscript">

evaluate(context, expression)

{

return context.nextNode().selectNodes(expression);

}

</msxsl:script>

However, I need to run the equivalent from dot net as an XSLT extension
object

The following code fails with a {"Index was outside the bounds of the
array." }

class XSLTExtensionObjects

{

public IXMLDOMNodeList evaluate(IXMLDOMNamedNodeMap context, string
expression)

{

return context.nextNode().selectNodes(expression);

}

}

XsltArgumentList xslArg = new XsltArgumentList();

XSLTExtensionObjects obj = new XSLTExtensionObjects();

xslArg.AddExtensionObject("urn:dynCs", obj);

fs = new FileStream(outData,FileMode.Create);

transform.Transform(doc,xslArg,fs,new XmlUrlResolver());

with this code in the XSLT:

<xsl:value-of select="dynCs:evaluate(($LossReport),string(./@from))"/>

(I have no trouble calling simple string based dot net extenstion functions)
Nov 12 '05 #1
1 3068
public string evaluate(XPathNodeIterator context, string expression)

{

// replace jscript return context.nextNode().selectNodes(expression);

{

context.MoveNext();

XPathNodeIterator iter = context.Current.Select(expression);

iter.MoveNext();

return iter.Current.Value;

}

catch "David Laub" <dl***@wheels.com> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
I have no problems running the following dynamic XPath evaluator form MSXSL:
<msxsl:script implements-prefix="dyn" language="jscript">

evaluate(context, expression)

{

return context.nextNode().selectNodes(expression);

}

</msxsl:script>

However, I need to run the equivalent from dot net as an XSLT extension
object

The following code fails with a {"Index was outside the bounds of the
array." }

class XSLTExtensionObjects

{

public IXMLDOMNodeList evaluate(IXMLDOMNamedNodeMap context, string
expression)

{

return context.nextNode().selectNodes(expression);

}

}

XsltArgumentList xslArg = new XsltArgumentList();

XSLTExtensionObjects obj = new XSLTExtensionObjects();

xslArg.AddExtensionObject("urn:dynCs", obj);

fs = new FileStream(outData,FileMode.Create);

transform.Transform(doc,xslArg,fs,new XmlUrlResolver());

with this code in the XSLT:

<xsl:value-of select="dynCs:evaluate(($LossReport),string(./@from))"/>

(I have no trouble calling simple string based dot net extenstion functions)

Nov 12 '05 #2

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

Similar topics

6
by: 0wl | last post by:
Hi, I am trying to get the value of child from xmlstr = """<p:root xmlns:p="http://tempuri.org/string"><p:child DataType="String">Hellpppp</p:child></p:root>""" using...
2
by: Neil Zanella | last post by:
Hello, I would like to know whether the mozilla web browser has built in support for searching XML documents via XPath expressions as with IE's xmlobject's and xmlDoc's function selectNodes() or...
2
by: Narayanan Sankaranarayanan | last post by:
Hi All, How do I dynamically evaluate expressions in VB.Net? Thanks in advance Narayanan Sankaranarayanan
3
by: Mitch Freed | last post by:
I have been using the JScript eval() method from C# to evaluate conditional logic at run-time. I found that implementing a solution similar to the example posted at:...
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
6
by: dotnetnoob | last post by:
i would like to know how i can build xpath expression dynamiclly. let's say i have a following xml file: <EventEnrollment InstanceNumber = "675"> <EventSource> <ObjectReference...
5
by: Daniel Frey | last post by:
Hello I'd like to match a dynamic node, given as a parameter to the stylesheet. Something like: <xsl:stylesheet ...> <xsl:param name="tomatch"/> <xsl:template match="{$tomatch}"> Hallo...
8
by: Sven | last post by:
Dear all, I'm trying to extract data from HTML using XPath in Java. Unfortunately the text contents of nodes may contain <br/tags which are not correctly interpreted, at least not for me ;) A...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.