472,951 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 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 3034
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.