![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Evaluate xpath sum() function with msxml [Thread Next] Re: Evaluate xpath sum() function with msxmlTo: NULL Date: 3/2/2005 1:26:00 PM Thanks Martin. Its a clever approach.
I was surprised that MSXML doesn't offer this facility - its available with
.Net. Perhaps they will introduce it with a new version of MSXML?
"Martin Honnen" <mahotrash@y...> wrote in message
news:%23LjMAkyHFHA.3472@T......
>
>
> Xerox wrote:
>
> > Can I not execute the xpath without a stylesheet?
> >
> > I want something like this: totalPrice = XMLDocument.Evaluate
> > ("sum(//item/@price)")
>
> MSXML doesn't provide an API for that so you would need to write a
> function of your own e.g. with JScript that builds up a stylesheet to
> get that result:
>
> function evaluateXPathExpression (node, xpathExpression) {
> var xslDocument = new ActiveXObject('Msxml2.DOMDocument');
> xslDocument.async = false;
> var loaded = xslDocument.loadXML([
> '<xsl:stylesheet ',
> 'xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">',
> '<xsl:output method="text" encoding="utf-16" />',
> '<xsl:template match="/">',
> '<xsl:value-of select="' + xpathExpression + '" />',
> '</xsl:template>',
> '</xsl:stylesheet>'
> ].join('\r\n'));
> if (loaded) {
> return node.transformNode(xslDocument);
> }
> else {
> return null
> }
> }
>
> var xmlDocument = new ActiveXObject('Msxml2.DOMDocument');
> xmlDocument.async = false;
> xmlDocument.load('test2005030202.xml');
>
> var result = evaluateXPathExpression(xmlDocument, "sum(//item/@price)");
>
> That approach needs refinement to make sure the quotes in the XPath
> expression passed to function do not clash with quotes in the XSL
> stylesheet but I think with MSXML you have no other way to evaluate an
> expression not yielding a node set or single node.
>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
