0% found this document useful (0 votes)
127 views

Soa XSLT Xpath Xquery

XSLT is a language for transforming XML documents into other XML documents or HTML. It consists of XSLT for transformations, XPath for navigating XML documents, and XSL-FO for formatting. XSLT is used to transform an XML source tree into a result tree by adding, removing, or rearranging elements and attributes. XPath is a language for selecting nodes in an XML document using path expressions. It is used by XSLT and XQuery. XQuery is a language for querying XML data that is built on XPath expressions and uses FLWOR expressions to select, filter, sort, and return data from XML documents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

Soa XSLT Xpath Xquery

XSLT is a language for transforming XML documents into other XML documents or HTML. It consists of XSLT for transformations, XPath for navigating XML documents, and XSL-FO for formatting. XSLT is used to transform an XML source tree into a result tree by adding, removing, or rearranging elements and attributes. XPath is a language for selecting nodes in an XML document using path expressions. It is used by XSLT and XQuery. XQuery is a language for querying XML data that is built on XPath expressions and uses FLWOR expressions to select, filter, sort, and return data from XML documents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

XSLT

Introduction
XSL: EXtensible Stylesheet Language.
Defined by the WWW Consortium (W3C)
CSS - Stylesheets for HTML
XSL - Stylesheets for XML

XSL consists of three parts:


XSLT - a language for transforming XML documents
XPath - a language for navigating in XML documents
XSL- FO - a language for formatting XML documents

XSLT
A common way to describe the transformation process is to say that XSLT
transforms an XML source -tree into an XML result tree
XSLT is used to transform an XML document into another XML document,
or another type of document that is recognized by a browser, like HTML
and XHTML
With XSLT you can add/remove elements and attributes to or from the
output file.
You can also rearrange and sort elements, perform tests and make
decisions about which elements to hide and display

XSLT - Transformation

Write an XML
Write an XSLT

Declaring XSLT:
<xsl:stylesheet version="1.0 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Link the XSLT to XML Document:
<?xml - stylesheet type="text/xsl" href= XSLName"?>

XSLT - Basics
xsl:template Element
Is used to build templates
The match attribute is used to associate a template with an XML element
xsl:value - of element to select values from the XML elements.
xsl:for- each element can be used to select every XML element of a specified node - set
Filtering the output: Filter the output from the XML file by adding a criterion to the select
attribute
Eg: <xsl:for-each select="catalog/cd[artist= SDTech'] />

XSLT - Basics

The <xsl:if> element is used to put a conditional test


against the content of the XML file
Eg: <xsl:if test="price &gt; 10"> </xsl:if>

The <xsl:choose> element is used in conjunction with


<xsl:when> and <xsl:otherwise> to express multiple
conditional tests.
Eg: <xsl:choose> <xsl:when test=" expression ">
... some output ...
</xsl:when>
<xsl:otherwise>
... some output
</xsl:otherwise>
</xsl:choose>

XSLT - Basics
Templates
Are rules to apply to the data
Similar to Procedures / Functions

Two ways to call the templates


<xsl:call -template>
<xsl:apply-templates>

XPath

XPath
XPath is a W3C recommendation
XPath contains a library of standard functions
XPath uses path expressions to select nodes or node - sets in an XML document.
Helps you navigate through the XML document.
Simple language consisting of path expressions.
XPath uses expressions to select nodes or node - sets in an XML document
Each vendor has already defined a lot of XPath functions

XPath Terminology Nodes:


Element
Attribute Text
Namespace
Processing- instruction
Comment
Document nodes
Relationship of Nodes:
Parent
Children
Siblings
Ancestors
Descendants

XPath Expressions
Expression Description

Nodename Select all nodes with the name nodename


/ Selects from root nodes
// Selects nodes in the document from the current node that match the selection no
matter where they are Selects the current node
Selects the parent of current node
@ Selects attributes

XPath Wildcards

Expression Description
* Matches any element node
@* Matches any attribute node
| Selects two nodes with AND
Selects the current node
Selects the parent of current node @ Selects attributes

XPath Axes

An axis defines a node - set relative to the current node.


AxisName Result

ancestor Selects all ancestors (parent, grandparent, etc.) of the current node
ancestor- or- self Selects all ancestors (parent, grandparent, etc.) of the current node
and the current node itself
attribute Selects all attributes of the current node
child Selects all children of the current node
descendant Selects all descendants (children, grandchildren, etc.) of the current node
descendant- or- self Selects all descendants (children, grandchildren, etc.) of the
current node and the current node itself
following Selects everything in the document after the closing tag of the current node
following - sibling Selects all siblings after the current node

namespace Selects all namespace nodes of the current node


parent Selects the parent of the current node
preceding Selects all nodes that appear before the current node in the document,
except ancestors, attribute nodes and namespace nodes
preceding - sibling Selects all siblings before the current node
self Selects the current node

XPath Functions

Lots of pre - defined functions. Few of them are below


AxisName Result
Round(number) Rounds the number argument to nearest integer Substring(string,
Returns sub - string from start position to specified length start, len)
String - length Returns length of the string
Day - from - datetime Returns the day of the date.
Max() Returns maximum value from set of numbers

XQuery
XQuery

XQuery is a W3C recommendation

XQuery : XML what SQL : database tables

XQuery is designed to query XML data.

XQuery is built on XPath expressions

XQuery is supported by all major databases.

XQuery - Basics

Uses functions to extract data from XML documents.

Uses path expressions to navigate through elements in an XML document.

Uses predicates to limit the extracted data from XML documents.

Can also transform the XML document into other format.

XPath terminology and relationship applies to XQuery also.

XQuery - Basics

FLWOR is an acronym for "For, Let, Where, Order by, Return".

The for clause selects all book elements under a node element into a variable.

The where clause selects only elements with a filter. The order by clause defines the
sort - order. Will be sort by the specified element.

The return clause specifies what should be returned.

XQuery - Syntax

XQuery is case - sensitive

XQuery elements, attributes, and variables must be valid XML names

An XQuery string value can be in single or double quotes

An XQuery variable is defined with a $ followed by a name

XQuery comments are delimited by (: and :), e.g. (: XQuery Comment :)

You might also like