XPath selects nodes and computes values: document.evaluate(expression, contextNode, resolver, resultType) (Widely available) returns an XPathResult. XSLT 1.0 stylesheets transform XML through XSLTProcessor.
const parse = (s) => new DOMParser().parseFromString(s, 'application/xml');
const xml = parse('<menu><dish price="9">Satay</dish><dish price="12">Curry</dish></menu>');
console.log(xml.evaluate('sum(//dish/@price)', xml, null, XPathResult.NUMBER_TYPE).numberValue);
const xsl = parse(`<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/menu"><ul><xsl:for-each select="dish">
<li><xsl:value-of select="."/> $<xsl:value-of select="@price"/></li>
</xsl:for-each></ul></xsl:template></xsl:stylesheet>`);
const processor = new XSLTProcessor();
processor.importStylesheet(xsl);
console.log(processor.transformToFragment(xml, document).firstChild.textContent.trim());Output
21 XSLTProcessor and XSLT Processing Instructions have been deprecated by all browsers. These features will be removed from this browser soon. See https://chromestatus.com/feature/4709671889534976. Satay $9 Curry $12
Chromium 4,389 , Gecko and WebKit 15,343 all plan to remove XSLT, whose aging libxslt C code keeps producing security bugs. Chrome 158 1 disables it on Stable, apart from an origin trial and enterprise policy lasting until Chrome 176. Transform on the server or in JavaScript, or load the WASM xslt_polyfill 47 (https://github.com/mfreed7/xslt_polyfill 47 ). XPath stays.