Transforming XML - PowerPoint PPT Presentation

Loading...

PPT – Transforming XML PowerPoint presentation | free to download - id: 1f4eac-ZDc1Z



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Transforming XML

Description:

The XSL Family. XPath (XML Path Language) XSLT (Extensible ... XSLT used to transform input and generate result tree. XSL-FO used to format output document ... – PowerPoint PPT presentation

Number of Views:64
Avg rating:3.0/5.0
Slides: 40
Provided by: johna90
Learn more at: http://isdscotland.org
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Transforming XML


1
Transforming XML
  • John Arnett, MSc
  • Standards Modeller
  • Information and Statistics Division
  • NHSScotland
  • Tel 0131 551 8794 (x2794)
  • E-mail John.Arnett_at_isd.csa.scot.nhs.uk

2
Course Contents
  • Terms and Definitions
  • Document Processing
  • Nodes and Trees
  • XPath Locating Nodes
  • XSLT Template Rules
  • XSLT Transformations
  • Summary
  • Find Out More

3
Terms and Definitions
  • The XSL Family
  • XPath (XML Path Language)
  • XSLT (Extensible Stylesheet Language
    Transformations)
  • XSL aka XSL-FO (Extensible Stylesheet Language
    Formatting Objects)

4
Terms and Definitions
  • XPath
  • Used to locate specific parts of an XML source
    document efficiently and effectively
  • XPath Version 1.0 W3C Recommendation

5
Terms and Definitions
  • XSLT
  • Used to transform XML documents to another XML or
    non-XML form esp. HTML
  • XSLT Version 1.0 W3C Recommendation
  • Version 2.0 W3C Working Draft
  • Uses XPath for locating document content

6
Terms and Definitions
  • XSL(-FO)
  • Used to format XML documents into fixed sized
    folios for printing or electronic display
  • XSL Version 1.0 W3C Recommendation
  • Uses XSLT for document transformation

7
Document Processing
  • Transformation and formatting
  • XPath used to locate nodes for input
  • XSLT used to transform input and generate result
    tree
  • XSL-FO used to format output document

8
Document Processing
source tree
Stylesheet Processor
transformation
formatting
stylesheet
Adapted from XSLT Basics slide presentation by
Paul Spencer, alphaXML
9
Trees and Nodes
  • XML document is viewed as a source tree
    containing different node types

10
Trees and Nodes
  • Transformation produces output document
  • Contains the result tree
  • May or may not be marked up

11
Trees and Nodes
  • XML Appointment example

lt! radiology appointment --gt ltAppointment
deptCodeRADIOgt ltPatient upiABC-123-456gtJoh
n Smith ltPhoneNogt0141 662 2673lt/ PhoneNogt
lt/Patientgt ltCliniciangtAlison
Younglt/Cliniciangt ltSlot attendDate08-05-2002gt
ltStartTimegt143000lt/StartTimegt lt/Slotgt
lt/Appointmentgt
12
Trees and Nodes
  • XPath view of Appointment source tree

13
XPath Locating Nodes
  • XPath expressions (location paths)
  • Used to navigate source tree and locate nodes for
    input
  • Comprised of one or more location steps
  • axis node test (optional) predicate
  • May contain functions
  • position(), count(node-set), last()

14
XPath Locating Nodes
  • Axes
  • Specify node locations relative to the current
    (context) node
  • Context node is specified using self
  • Forward traversal
  • child, attribute, descendant-or-self, descendant,
    following, following-sibling, namespace
  • Reverse traversal
  • parent, ancestor, ancestor-or-self, preceding,
    preceding-sibling

15
XPath Locating Nodes
  • Node tests
  • Refine the node set specified by the axis
  • select all nodes with same basic node-type
  • node() select all nodes regardless of type
  • text() select all text nodes
  • comment() select all comment nodes
  • processing-instruction() select all processing
    instruction nodes
  • select all nodes with specified node name

16
XPath Locating Nodes
  • Locating a named child node
  • childAppointment/childClinician

17
XPath Locating Nodes
  • Locating a named attribute node
  • childPatient/attributeupi

18
XPath Locating Nodes
  • Locating descendants
  • /descendant-or-selfnode()/childtext()

19
XPath Locating Nodes
  • Locating a nodes parent
  • parentnode() ? parent

20
XPath Locating Nodes
  • Using wildcards
  • child

21
XPath Locating Nodes
  • Abbreviating location steps
  • child and text()? can usually be omitted
  • /childAppointment/childClinician/childtext()
    ? /Appointment/Clinician (? for text-only nodes)
  • attribute ? _at_
  • Patient/_at_upi
  • self()node ? .
  • parentnode() ? ..

22
XPath Locating Nodes
  • Abbreviating Location Paths
  • /descendant-or-selfnode()/ ? //
  • /descendant-or-selfnode()/childtext() ?
    //text()

23
XSLT Template Rules
  • Template Rule
  • XPath pattern specifies nodes to match
  • ltxsltemplate matchAppointment"gt
  • lt/xsltemplategt
  • Output template contains XSLT processing
    instructions
  • ie. for processing input and creating new element
    and attribute nodes

24
XSLT Template Rules
  • Template rule for creating a Patient Id element
    from Appointment

ltxsltemplate match"Appointment"gt ltPatientIdgt
ltIdgt ltxslvalue-of select"Patient/_at_upi"/gt lt/
Idgt ltNamegt ltxslvalue-of select"Patient/text
()"/gt lt/Namegt lt/PatientIdgt lt/xsltemplategt
25
XSLT Template Rules
  • Patient Id output from template rule

ltPatientIdgt ltIdgtABC-123-456lt/Idgt ltNamegtJohn
Smithlt/Namegt lt/PatientIdgt
26
XSLT Template Rules
  • Appointment List

ltAppointmentListgt ltAppointment
deptCodeRADIOgt ltAppointment
deptCodePHYSIOgt ltAppointment
deptCodeGMEDgt ltAppointment
deptCodeGMEDgt ltAppointment
deptCodeCMEDgt ltAppointment
deptCodePHYSIOgt ltAppointment
deptCodeCMEDgt lt/AppointmentListgt
27
XSLT Template Rules
  • Applying Template Rules
  • Creating a list of patient ids

ltxsltemplate match"AppointmentList"gt ltPatientLi
stgt ltxslapply-templates/gt lt/PatientListgt lt/xsl
templategt ltxsltemplate match"Appointment"gt ltPa
tientIdgt ltIdgtltxslvalue-of select"Patient/_at_upi"
/gtlt/Idgt ltNamegtltxslvalue-of select"Patient/text
()"/gtlt/Namegt lt/PatientIdgt lt/xsltemplategt
28
XSLT Template Rules
  • Patient Ids list output

ltPatientListgt - ltPatientIdgt  ltIdgtABC-123-456lt/
Idgt   ltNamegtJohn Smithlt/Namegt  
lt/PatientIdgt ltPatientIdgt ltPatientIdgt
ltPatientIdgt lt/PatientListgt
29
XSLT Transformations
  • Stylesheets

ltxslstylesheet version"1.0" xmlnsxsl"http//ww
w.w3.org/1999/XSL/Transform"gt ltxsltemplate
match"/"gt ltxslapply-templates/gt lt/xsltemplat
egt ltxsltemplate match"pattern1"gt lt!-- XSLT
processing instructions --gt lt/xsltemplategt
ltxsltemplate match"pattern2"gt ltxsltemplate
match"pattern3"gt lt/xslstylesheetgt
30
XSLT Transformations
stylesheet
source tree
read template
yes
find source nodes
more templates?
no
format result tree
transform source
nodes to result nodes
display formatted tree
Adapted from XSLT Basics slide presentation by
Paul Spencer, alphaXML
31
XSLT Transformations
  • XSLT - rich syntax that enables
  • Copying
  • Conditional processing
  • ltxslif test_at_deptCode PHYSIO"gtlt/xslifgt
  • Iteration and sorting
  • ltxslfor-each selectAppointment"gtlt/xslfor-eachgt
  • Applying XPath functions
  • ltxslvalue-of select"concat(_at_deptCode,
    generate-id(.))"/gt
  • Creating new nodes

32
XSLT Transformations
  • xslstylesheet
  • xsloutput
  • xsltemplate
  • xslapply-templates
  • xslvalue-of
  • xsltext
  • xslif
  • xslchoose, xslwhen and xslotherwise
  • xslfor-each
  • XSLT Elements

33
XSLT Transformations
  • Copying and conditional processing
  • Creating a list of PHYSIO appointments

ltxsltemplate match"AppointmentList"gt ltPhysioApp
ointmentsgt  ltxslapply-templates /gt  
lt/PhysioAppointmentsgt  lt/xsltemplategt
ltxsltemplate match"Appointment"gt ltxslif
test"_at_deptCode 'PHYSIO'"gt  ltxslcopy-of
select"." /gt   lt/xslifgt  lt/xsltemplategt
34
XSLT Transformations
  • PHYSIO appointments list output

ltPhysioAppointmentsgt - ltAppointment
deptCode"PHYSIO"gt ltPatient
upi"EFG-567-012"gt  ltCliniciangtMark
Boyddlt/Cliniciangt ltSlot attendDate"05-08-200
2"gt  lt/Appointmentgt ltAppointmentdeptCode"
PHYSIO"gt  lt/PhysioAppointmentsgt
35
XSLT Transformations
  • Iteration and sorting
  • Creating an appointment summary table

lttable border"1"gt ... ltxslfor-each
select"Appointment"gt ltxslsort
select"_at_deptCode" order"ascending"/gt lttrgt lt
tdgtltxslvalue-of select"Patient/text()"/gtlt/tdgt
... lt/trgt lt/xslfor-eachgt lt/tablegt
36
XSLT Transformations
  • Appointments summary table output

37
XSLT Transformations
  • Creating new nodes
  • XSLT instructions

ltxslelement name"MyNewElement"gt ltxslattribute
name"myNewAttribute"gtvalue lt/xslattributegt lt/xs
lelementgt
  • XSLT output

ltMyNewElement myNewAttribute"value"/gt
38
In Summary
  • Suite of XML-based technologies XPath, XSLT and
    XSL-FO
  • Transformation performed by applying style sheet
    to source document
  • XPath used to navigate source tree
  • XSLT template rules specify nodes to match and
    contain processing instructions
  • Provides a rich syntax for transforming documents
    into XML and non-XML forms

39
Find Out More
  • World Wide Web Consortium
  • www.w3.org
  • Getting started with XSLT and XPath by
    Ken Holman (Parts 1, 2 3)
  • www.xml.com/pub/a/2000/08/holman/s2_1.html
  • Robert DuCharme's Transforming XML column
  • www.xml.com/pub/q/transformingxml
About PowerShow.com