471,594 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 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 2956
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by 0wl | last post: by
2 posts views Thread by Neil Zanella | last post: by
2 posts views Thread by Narayanan Sankaranarayanan | last post: by
3 posts views Thread by Mitch Freed | last post: by
9 posts views Thread by David Thielen | last post: by
6 posts views Thread by dotnetnoob | last post: by
5 posts views Thread by Daniel Frey | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.