+ All Categories
Home > Documents > Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

Date post: 21-Jan-2016
Category:
Upload: gwen-nichols
View: 229 times
Download: 0 times
Share this document with a friend
10
Dom and XSLT • Dom – document object model • DOM – collection of nodes in a tree
Transcript
Page 1: Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

Dom and XSLT

• Dom – document object model

• DOM – collection of nodes in a tree

Page 2: Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

JAXP – Java API for xml processing

Page 3: Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

Brief Primer on XML

Page 4: Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

What is XSLT?

Page 5: Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

How Does XSLT Relate to XML?

• XSLT is well formed XML.– Only need to learn new syntax to learn XSLT

(if you know XML)

• Transforms XML documents– From one DTD to another

• DTD – document type definition– To learn how to write DTD’s you had to learn

new structures.

• Uses XPath to match patterns in XML

Page 6: Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

History of XSLT

•XSLT is part of XSL specification

•Expanded into separate specification

•Relies on XPath for some of its functionality

Page 7: Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

Why Use XSLT?

• W3C Standard

• Open Source

• Can add functionality to program without recompiling

• Rapid development & ease of code reuse

• XSLT is XML

Page 8: Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

Alternatives to XSLT

• XML Libraries such as SAX used in conjunction with general purpose programming language such as Java

• Custom programming solution

• Tighter integration with business partners, e.g., work with common DTD / Schema

Page 9: Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

Example XSLT Stylesheet

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="type"><brew>

<xsl:apply-templates/></brew>

</xsl:template><xsl:template match="price"/><!-- All other elements --><xsl:template match="*|@*|text()">

<xsl:copy><xsl:apply-templates select="*|@*|

text()"/></xsl:copy>

</xsl:template></xsl:stylesheet>

<?xml version="1.0" encoding="UTF-8"?><beer color="dark">

<product>Sam Adams</product><type>ale</type><price>6.99</price>

</beer>

Input File

Output File

<?xml version="1.0" encoding="UTF-16"?><beer color="dark">

<product>Sam Adams</product><brew>ale</brew>

</beer>

XSLT File

Page 10: Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.

Demonstration


Recommended