Transforming XML Part II - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Transforming XML Part II

Description:

Transforming XML Part II XML Document Transformation with XSLT John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland – PowerPoint PPT presentation

Number of Views:107
Avg rating:3.0/5.0
Slides: 24
Provided by: JohnAr157
Category:
Tags: xml | part | transforming

less

Transcript and Presenter's Notes

Title: Transforming XML Part II


1
Transforming XML Part II
  • XML Document Transformation with XSLT

John Arnett, MSc Standards Modeller Information
and Statistics Division NHSScotland Tel 0131 551
8073 (x2073) mailtoJohn.Arnett_at_isd.csa.scot.nhs.u
k http//isdscotland.org/xml
2
Contents
  • XML Document Processing
  • XSL Stylesheets
  • XSLT
  • Template Rules
  • Processing Instructions
  • Summary
  • Find Out More

3
XML 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

4
XSL Stylesheets
  • The Stylesheet element

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"pattern"gt lt!-- XSLT
processing instructions --gt lt/xsltemplategt lt!--
More template rules... --gt lt/xslstylesheetgt
5
XSL Stylesheets
  • Template Rules

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"pattern"gt lt!-- XSLT
processing instructions --gt lt/xsltemplategt lt!--
More template declarations... --gt lt/xslstyleshee
tgt
6
XSL Stylesheets
  • Processing Instructions

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"pattern"gt lt!-- XSLT
processing instructions --gt lt/xsltemplategt lt!--
More template declarations... --gt lt/xslstyleshee
tgt
7
XSL Stylesheets
Source Tree
Style sheet
read template
yes
find source nodes
more templates?
no
Result Tree
evaluate processing instructions
Adapted from XSLT Basics slide presentation by
Paul Spencer, alphaXML
8
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

9
XSLT Template Rules
  • Template rule for creating PatientId 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
10
XSLT Template Rules
  • PatientId output from template rule

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

ltAppointmentListgt ltAppointment
deptCodeRADIOgt ltAppointment
deptCodePHYSIOgt ltAppointment
deptCodeGMEDgt ltAppointment
deptCodeGMEDgt ltAppointment
deptCodeCMEDgt ltAppointment
deptCodePHYSIOgt ltAppointment
deptCodeCMEDgt lt/AppointmentListgt
12
XSLT Template Rules
  • Applying Template Rules
  • Creating a list of PatientIds

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
13
XSLT Template Rules
  • PatientIds list output

ltPatientListgt - ltPatientIdgt  ltIdgtABC-123-456lt/
Idgt   ltNamegtJohn Smithlt/Namegt  
lt/PatientIdgt ltPatientIdgt ltPatientIdgt
ltPatientIdgt lt/PatientListgt
14
XSLT Processing Instructions
  • XSLT - rich syntax that enables
  • Copying
  • Conditional processing
  • ltxslif test_at_deptCode PHYSIOgt...
  • Iteration and sorting
  • ltxslfor-each selectAppointmentgt...
  • Application of XPath functions
  • ltxslvalue-of select"concat(_at_deptCode,
    generate-id(.))"gt...
  • Creation of new nodes

15
XSLT Processing Instructions
  • XSLT Elements
  • xsltext
  • xslif
  • xslchoose
  • xslwhen
  • xslotherwise
  • xslforeach
  • xslstylesheet
  • xsloutput
  • xsltemplate
  • xslapply-templates
  • xslvalue-of

16
XSLT Processing Instructions
  • 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
17
XSLT Processing Instructions
  • 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
18
XSLT Processing Instructions
  • Iteration and sorting
  • Creating an appointments 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
19
XSLT Processing Instructions
  • Appointments summary table output

20
XSLT Processing Instructions
  • Creating new nodes
  • XSLT instructions

ltxslelement name"MyNewElement"gt ltxslattribute
name"myNewAttribute"gt value lt/xslattributegt
lt/xslelementgt
  • XSLT output

ltMyNewElement myNewAttribute"value"/gt
21
In Summary
  • XSL stylesheets contain one or more XSLT template
    rules
  • Template rules specify nodes to match and contain
    XSLT processing instructions
  • XSLT has a rich syntax for transforming documents
    into XML and non-XML outputs

22
Find Out More
  • W3C XSL Transformations (XSLT) v1.0
    Specification
  • www.w3.org/TR/xslt
  • Getting started with XSLT and XPath by Ken Holman
    (Parts 1, 2 3)
  • www.xml.com/pub/a/2000/08/holman/s2_1.html
  • ZVON.org - XSLT Tutorial
  • www.zvon.org/xxl/XSLTutorial/

23
Find Out More
  • Robert Ducharmes Transforming XML column
  • www.xml.com/pub/q/transformingxml
  • TopXML XSLT Stylesheets
  • www.topxml.com/xsltstylesheets/default.asp
Write a Comment
User Comments (0)
About PowerShow.com