XSLT (2024)

Name

sum() Function — Converts all nodes in the argument node-set to numbers, and then returns the sum of all of those numbers. If any node in the node-set can’t be converted to numbers (passing them to the number() function returns NaN), the sum() function returns NaN.

Synopsis

number sum( node-set )

Inputs

A node-set. Any node in the node-set that is not a number is converted to a number as if it were passed to the number() function, then the numeric values of all of the nodes are summed.

See Also
What is XSL?

Output

The sum of the numeric values of all of the nodes in the argument node-set. If any node in the argument node-set cannot be converted to a number, the sum() function returns NaN.

Defined in

XPath section 4.4, Number Functions.

Example

We’ll demonstrate the sum() function against the following XML document:

<?xml version="1.0"?><report> <title>Miles Flown in 2001</title> <month sequence="01"> <miles-flown>12379</miles-flown> <miles-earned>35215</miles-earned> </month> <month sequence="02"> <miles-flown>32857</miles-flown> <miles-earned>92731</miles-earned> </month> <month sequence="03"> <miles-flown>19920</miles-flown> <miles-earned>76725</miles-earned> </month> <month sequence="04"> <miles-flown>18903</miles-flown> <miles-earned>31781</miles-earned> </month></report>

Here is a stylesheet that uses the sum() function:

<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="newline"> <xsl:text> </xsl:text> ...
XSLT (2024)

FAQs

XSLT? ›

XSLT (eXtensible Stylesheet Language Transformations) is the recommended style sheet language for XML. XSLT is far more sophisticated than CSS. With XSLT you can add/remove elements and attributes to or from the output file.

What is XSLT used for? ›

XSLT is most often used to convert data between different XML schemas or to convert XML data into web pages or PDF documents.

Is XSLT outdated? ›

Isn't XSLT really old? The original XSL Transformations (XSLT) Version 1.0 XSLT specification is now over 20 years old, however pieces of software built around XSLT are still remain relevant technology, though XSLT itself is a language that is not likely to generate a huge new following in 2024.

What is the difference between XSLT and XML? ›

XML contains data. XSLT is a way to transform the XML data into something else. One of the simpler examples: You have an XML file with information on all your books but you want this is as a webpage.

What is the difference between CSS and XSLT? ›

XSLT is a Turing complete language, while CSS is not; this demonstrates a degree of power and flexibility not found in CSS.

What are the advantages of using XSLT? ›

Here are some of the advantages of using XSLT.
  • There is no dependency on programming. ...
  • By simply modifying the transformations in the XSL file, it is possible to alter the output. ...
  • Moreover, it applies user-defined transformations to an XML document. ...
  • To locate elements/attribute within an XML document, XPath used by XSLT.
Jul 3, 2019

Should I use XSLT? ›

XSLT has several important advantages over all other programming languages when it comes to XML data transformation: It has been designed to work with enterprise XML technologies. It makes most data conversion tasks very easy to understand and implement. Solutions written using XSLT can be proven to be correct.

Can we use XSLT for JSON? ›

XSLT JSON is an alternative of XML defined to structure data used for data interchange between a server and web applications and a subset of JavaScript Language. XSLT 3.0 provides responsibilities for handling JSON data(importing/exporting). JSON is Javascript Object Notation tied up with the web services.

Is XSLT a scripting language? ›

From a programmer's point of view, XSLT is a programming language for processing XML data — that is, transforming XML documents. As such, it supports the following: A small set of flexible data types: Boolean, number, string, node-set, and external objects.

Can we convert XML to XSLT? ›

You can convert part or all of an XML document and select or rearrange the data using the XPath query language and the built-in functions of XSLT. XSLT is commonly used to convert XML to HTML, but can also be used to transform XML documents that comply with one XML schema into documents that comply with another schema.

What is the difference between XPath and XSLT? ›

Extensible Stylesheet Language: Transformations (XSLT) is a language for transforming the structure of XML documents. It is designed for use as part of Extensible Stylesheet Language (XSL). XML Path Language (XPath) is an XSL sub-language that is designed to be used with XSLT.

What is the difference between XSLT and FTL? ›

By contrast, XSLT is really a tree-transformation tool; it takes an input tree and manipulates it into an output tree. The FreeMarker Template Language (FTL) is based on a much more conventional programming model -- the procedural or imperative model. You can define variables and functions.

What would you use XSLT for in the ETL process? ›

In the transform step of the ETL (Extract, Transform, Load) process, XSLT (Extensible Stylesheet Language Transformations) may be very helpful in transforming extracted data into a format that can be loaded into the destination system (XSLT Transformation, n.d.).

Why do we use XSLT mapping? ›

XSLT mapping is an effective method for facilitating data transformations in the context of SAP CPI. You can declare a series of rules that describe how the source XML data should be converted into the appropriate target format using this tool.

Top Articles
Latest Posts
Article information

Author: Velia Krajcik

Last Updated:

Views: 5460

Rating: 4.3 / 5 (74 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.