EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

XPath Functions

Secondary Sidebar
XML Tutorial
  • Basic
    • What is XML?
    • XML Tags
    • XML URL
    • XPath Sibling
    • XML root element
    • XML Encryption
    • XML Parsing php
    • xml parsing with java
    • Dataset XML
    • XML Parser in C#
    • XML Tree
    • XML boolean
    • XML sitemap
    • XML Array
    • XML reserved characters
    • XML Viewer
    • XML Uses
    • XML Special Characters
    • XML generator
    • XML file format
    • XML DOM
    • XML ampersand
    • XML Mapping
    • XML File
    • XML Element
    • XML HttpRequest
    • XML XSD
    • XML Schema
    • XML Namespaces
    • XML Comments
    • XML Attributes
    • XML Encoding
    • XML Validation
    • XML CDATA
    • XML Database
    • XML Technologies
    • XML Error
    • XML DTD
    • XML Date
    • XML Parsers
    • String in XML
    • XML with CSS
    • XML Versions
    • XML Features
    • XML Commands
    • Servlet web.xml
    • XPath Injection
    • XPath Functions
    • XPath starts-with
    • XPath Selector
    • XPath Count
    • XPath XML
    • XML Parsing in Oracle
    • XML parsing in python
  • Xpath
    • What is XPath?
    • XPath namespace
    • XPath for JSON
    • XPath Last Element
    • Xpath Substring
    • XPath First Element
    • XPath local-name
    • XPath Multiple Attributes
    • XPath Matches
    • XPath Position
    • XPath Index
    • XPath regex
    • XPath id contains
    • XPath innertext
    • XPath Multiple Conditions
    • XPath Helper
    • XPath Generator
    • XPath ID
    • XPath Locator
Home Software Development Software Development Tutorials XML Tutorial XPath Functions

Introduction to XPath Functions

XPath functions are implemented using the CDC replication engine for the event server. The XPath function is uniquely defined by using the name, so creating a different function with the same name is impossible. Still, we can use different types of signatures, so the XPath function overloading is not permitted. XPath function will accept arguments of various kinds, which defines the signature of the argument type.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,064 ratings)

XPath Functions

What are XPath Functions?

XPath defines each function with specifications by using a standard format. The function name is the qname defined and adhered to in syntactic conversions. The XPath function name is composed of English words and separated by the word using hyphens. We can use abbreviations only when there is precedent in other programming languages. If the name of the function contains the name of the data type, then it will have inter-capitalized spelling used in a function name.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

When we pass argument ID in another type, the argument is converted into a string as if we are calling the function of the string. The string function will splitted into the list of whitespace-separated tokens. If the result in the node set contains the elements in the same documents as per the context node, it is equal to the token list.

XPath Functions Types

There are different types of XPath functions available.

Below is the type of function which was available in XPath as follows:

  • Node function
  • Numeric function
  • String function
  • Boolean function

There are four types of XPath functions available; also, this function contains its subtypes as follows:

1. Boolean Function

XPath Boolean function is used to convert the arguments into the Boolean.

Below is the XPath boolean function as follows:

  • Not
  • True
  • False
  • Long

Example:

Code:

<p xml:lang="en-us">sal</p>
<p xml:lang="en">sal</p>

Output:

XPath Functions 1

2. Node Function

The XPath node function provides the node-related function as follows:

  • Node – This function is used to return the value of the node.
  • Text – This function returns the text value of a specific node.
  • Comment – It is used to return the particular comment node.
  • Last – This function is used to total context size from a given context.
  • Position – This function is used to return the position of an element.
  • Name – This function will return the last expression string name.
  • Local-name – This function will return the previous expression string local name.

Example:

Code:

<xsl:value-of select="stud_name/node()"/>
<p>local-name() example : <xsl:value-of select = "local-name(//report/stud_name)"/> </p>

Output:

XPath Functions 2

3. Numeric Function

XPath numeric function provides the following numeric function as follows. Below is the numeric function available in XPath as follows.

  • Count
  • Sum
  • Div
  • Number
  • Floor
  • Round
  • Ceiling

Example:

Code:

<p>01.35 number : <xsl:value-of select = "number('01.35')"/> </p>
<p>01.35 value : <xsl:value-of select = "floor(01.35)"/> </p>

Output:

XPath Functions 3

4. String Function

XPath string function provides the following string function as follows. Below is the string function available in XPath as follows.

  • String
  • Concat
  • Start-with
  • Contains
  • Substring
  • String-length
  • Substring-after
  • Substring-before
  • Normalize-space

Example:

Code:

<p>starts-with() example : <xsl:value-of select="starts-with('String XPath function.','String')"/> </p>
<p>contains() example : <xsl:value-of select="contains('String XPath function.','XPath')"/> </p>

Output:

String Function

XPath Functions Purpose

Each XPath function in the function library is specified using a prototype; it will also give the return type, the function’s name, and the argument type. If the type of argument is followed with the question mark, then the type of argument is optional, or otherwise, we require this argument. The function will select the element as per the unique ID. When our argument ID is the node set type, our result is the union of each node’s string value into the node-set argument.

Each function contains a different name; as per the function, we can pass one or more arguments to the function. After passing the argument, it will change the behavior of a function. Using the function, we can obtain the result. The function is essential and valuable in XPath.

Example of XPath Functions

The below example shows the XPath function as follows. In the below example, we are creating the project of XPathFunction. In the below example, we are making the template of the project name as XPath function into spring boot.

1. While creating the project into the XPath function using spring boot, we provided the group’s name as com.example, artifact name as XPathFunction, project name as XPathFunction, and selected java version as 11.

Group – com.example
Artifact name – XPathFunction
Name – XPathFunction
Spring boot – 2.6.7
Project – Maven
Java – 11
Package name – com.example. XPathFunction
Project Description – Project for XPathFunction
Dependencies – Spring web
Packaging – Jar

XPath function using spring boot

2. In the figure below, we can extract the project name as XPathFunction and open this project using the spring tool suite.

extract the project name as XPathFunction

3. In the below step, we are checking the structure of the XPath Function project. Also, we are seeing the project dependency, which was added to the pom.xml file. Also, we are checking all the structures of the XPath Function example project.

structure of the XPath Function project

4. Now, we are creating the xml file for an example of the XPath Function. We are making a file name stud.xml.

Code:

<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "studs.xsl"?>
<class>
<stud rollno = "101">
<stud_fname> ABC </stud_fname>
<stud_lname> PQR </stud_lname>
<stud_marks> 70 </stud_marks>
</stud>
<stud rollno = "102">
<stud_fname> PQR </stud_fname>
<stud_lname> XYZ </stud_lname>
<stud_marks> 75 </stud_marks>
</stud>
</class>

Output:

creating the xml file

5. Now, we are creating the xsl file for an example of the XPath Function. We are building a file name as a stud.xsl.

Code:

<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "example.com">
<xsl:template match = "/">
<html>
<body>
<h2>stud</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Stud name</th>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

Output:

creating the xsl file

creating the xsl file

Conclusion

XPath defines each function with specifications by using a standard format. The function name is the qname defined and adhered to in syntactic conversions. XPath functions are implemented using the CDC replication engine for the event server. XPath function is uniquely defined by using the name.

Recommended Articles

This is a guide to XPath Functions. Here we discuss the introduction, XPath function types, purpose, and example. You may also have a look at the following articles to learn more –

  1. XPath Sibling
  2. XPath Ancestor
  3. XPath regex
  4. XPath namespace
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - All in One Software Development Bundle (600+ Courses, 50+ projects) Learn More