soa xslt xpath xquery

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

Upload: crecykengmailcom

Post on 14-Jul-2016

4 views

Category:

Documents


1 download

DESCRIPTION

Soa Xslt Xpath Xquery

TRANSCRIPT

Page 1: Soa Xslt Xpath Xquery

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">

Page 2: Soa Xslt Xpath Xquery

∗ 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>

Page 3: Soa Xslt Xpath Xquery

... 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 ∗

Page 4: Soa Xslt Xpath Xquery

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

Page 5: Soa Xslt Xpath Xquery

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

 

Page 6: Soa Xslt Xpath Xquery

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 :)

Page 7: Soa Xslt Xpath Xquery