Wednesday, February 18, 2026

XSLT Datatypes

 The following are the different datatypes:

  • Boolean

  • Number

  • String

  • Node-set

Boolean Datatype

The Boolean datatype returns true or 
false. 
Functions in XPath, such as true(), false(), and lang(), return values of the Boolean datatype. 

Ex: you can declare a function that checks whether or not a particular node exists in the document. This function returns true if the node exists and returns false if the node does not exist.

Number Datatype

The number datatype represents numeric values in XPath.
The number datatype can store up to 64-bit floating-point numbers.
XPath does not support scientific notation of floating point values. As a result, you cannot perform relational operations such as greater than, greater than or equal to, lesser than, and lesser than or equal to, on variables of the number datatype. 

Functions of XPath, such as sum(), round(), ceil(), floor(), number(), and format-number(), are examples of functions that return values of the number datatype.

String Datatype

A string is a collection of characters that are enclosed in single or double quotes.    

XPath provides several functions to perform string related operations. 
For example, the translate() function converts upper case characters to lower case, and vice-versa. 
The string-length() function enables you to retrieve the number of characters in a string. 
the string-length() function to find the length of a string

The Strlen.xsl File


<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> The string length of "California" is <xsl:value-of select= "string-length('California')"/> </xsl:template> </xsl:transform>

the string-length() function is used to count the number of characters in the word, California.

Node-Set

A node-set is a group of nodes in a source tree. The nodes in the node-set can be from more than one source tree. The node-set can also contain nodes from a temporary tree or from a tree, which is imported to the current document through an external function.

Operators

Operators are symbols to represent operations, and are used with operands to form an expression. The syntax to use an Operator in XSLT is:

OperatorName | MultiplyOperator | <</>> | <<//>> | <<+>> |<<|>>| <<->> | <<=>> | <<!=>> | << < >> | << > >> | << <= >> | << >= >>


 Expression.xsl File


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:variable name="p" select="1000"/> <xsl:variable name="n" select="3"/> <xsl:variable name="r" select="1.5"/> <xsl:variable name="h" select="100"/> <xsl:variable name="mul" select="($p*$n*$r) div $h"/> The value of the expression is <xsl:value-of select="$mul"/> </xsl:template> </xsl:stylesheet>

the operators, * and div, are applied to the value stored in the variables, p, n, r, and h, and the resultant value is stored in the variable, mul.

XPath Expressions

You can use XPath expressions to define the location of a particular element in an XML document during the XSLT transformation process.

Elements.xsl File

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet>

the match="/" criteria locates the document root.
The select="." expression specifies that the XSL file

No comments:

Post a Comment

SOA Overview Part-1

  Middleware It provides a mechanism for the process to interact with other processes running on multiple network machines. Advantages...