Title: Converting XMLFiles with XSLT and XPath
1Converting XML-Files with XSLT and XPath
XSLT eXtensible Stylesheet Language
Transformations Version 1.0 XPath eXtensible
Path Language Version 1.0
PetriNet-AG GraGra-AG 2001
2Outline of the Talk
- Motivation
- XML Overview
- Features of XPATH
- Features of XSLT
- Converting XML-Files with XSLT and XPath
- Using XSLT and XPATH with Java
- Example PNML 1.0 ? GTS 1.0
- Summary and Outlook
3Motivation
- Graph Transformation System (GTS)
- GenGEd, AGG (TU-Berlin)
- Petri Net Markup Language (PNML)
- Petri-Net-Kernel (PNK) (HU-Berlin)
- Problem Creating a Converting-Tool
GenGEd
PNK
Convert
Xml-Files to GTS.dtd
Xml-Files to stNet.xsd
4XML Overview
- strict syntax rules
- additional syntax rules Document Type
Definitions (DTDs), XMLSchema - structured interchange facilities for documents
- replaces ASCII
- tree-like structured documents
- also usable for interchanging data structures
- more and more standard for exchange formats
- comes up with a lot of tool support
http//www.w3.org/TR/REC-xml
5XML Grammars Document Type Definition (DTD) and
XMLSchema
- Document Type Definition (DTD)
- defines a concrete syntax for elements and
attributes in a xml-file - the DTD-syntax is not xml-based
- limited possibilities to define abstract data
types - XMLSchema
- syntax is xml-based
- allows redefinitions of data types
- allows conditions for elements and attributes
- allows the use of all primitive data types
- e.g. integer and float
http//www.w3.org/1999/XMLSchema
6XML Overview A simple XML-File
lt?xml version1.0?gt lt!DOCTYPE user SYSTEM
user.dtdgt ltuser id007gt ltnamegtRoger
Moorelt/namegt ltemailgtmoore_at_cinema.uklt/emailgt lt/use
rgt
- Basic Concepts
- Logically and physically structured documents
- tree-like structure
- each tree node has
- start tag
- end tag
- set of subtags
- set of attributes
Based on the DTD
lt!ELEMENT user (name, email?)gt lt!ATTLIST user
id ID
REQUIREDgt lt!ELEMENT name (PCDATA)gt lt!ELEMENT
email (PCDATA)gt
7XSL (XSLT, XPath) Overview
- XSL (eXtensible Stylesheet Language) is a
xml-based language for transforming xml-documents
to other xml-documents (e.g. based on another
DTD), html, text-files or other types of
documents - XSL contains the languages
- XPath expressions for selecting elements in a
document - XSLT (XSL Transformations)
- other languages e.g. XLink, XPointer, ...
http//www.w3.org/TR/xsl
8Features of XPath
- identifies particular parts in XML documents
- Expressions along the tree structure of XML
documents - Examples
- childchapter
- Selects all subordinated elements of chapter
- childselfchapter
- Selects all chapter elements of the context
element - id(a23)/childchapterposition()5
- Selects the fifth child-element with the name
chapter of the element with the unified ID a23
http//www.w3.org/TR/xpath
9Features of XSLT (XSL Transformations)
- tree-oriented transformation language based on
XML - uses XPath expressions for
- conditional parsing if / while / test / ...
- selecting parts of the document match / select /
value-of / template / ... - manipulation of strings and numbers
- vocabulary for specifying formating e.g. sorting
- variable output formats e.g. xml, html, plain
text, ...
http//www.w3.org/TR/xslt
10Converting XML-Files with XSLT and XPath
Output
Converting Rules Stylesheet (XSL)
XSLT (eXtensible Stylesheet Language
Transformations)
XML-File (Out-DTD)
XPath
HTML
Input
XSLT-Engine based on Java
XML-File (Input-DTD)
Plain Text
...
11Example of a Stylesheet (XSL) Transformation
With stylesheet (xsl)
ltxsltemplate matchusergt ltmeetinggt ltxslvalue-o
f selectnamegt lt/meetinggt ltcontactgt ltxslvalue-o
f selectemailgt lt/contactgt lt/xsltemplategt
Converts
lt?xml version1.0?gt lt!DOCTYPE user SYSTEM
user.dtdgt ltuser id007gt ltnamegtRoger
Moorelt/namegt ltemailgtmoore_at_cinema.uklt/emailgt lt/use
rgt
ltmeetinggtRoger Moorelt/meetinggt ltcontactgtmoore_at_cine
ma.uklt/contactgt
To
12Java API for XML Parsing (jaxp Vers. 1.1)
- DOM (Document Object Model) Parser
- useful to verify a xml-file according to a DTD
e.g. tfs/tools/showXML - Tool - SAX (Simple API for XML) Parser
- Interface for event-based parsing of XML
documents - Transformation Factory
- new feature in version 1.1
- XML Inputfile
- Converting-Rules XSL-File with XPath Rules
- Output XML (Out-DTD) / HTML / Text / ...
13Example PNML 1.0 ? GTS 1.0
- Petri-Net-Markup-Language Vers. 1.0 ? Graph
Transformation System Vers. 1.0 - Java Petri-Net-Kernel (alpha-Version) of the
HU-Berlin could export place transition nets in
PNML 1.0 based on the XMLSchema stNet.xsd - Converting Tool at
- tfs/tools/XMLConv
- gt pnml2gts.sh ltinputfilegt ltoutputfilegt
- Output xml-file based on the GTS-DTD
- old version with EdgeType and NodeType
- Problem New GTS-DTD (changed for AGG) which
doesnot work with GenGEd
14Example PNML 1.0 ? GTS 1.0 stNet.xsd
- lt?xml version"1.0" encoding"UTF-8"?gt
- lt!DOCTYPE xsdschema PUBLIC "-//W3C//DTD
XMLSCHEMA 19991216//EN" "" - lt!ENTITY p 'xsd'gt
- lt!ENTITY s 'xsd'gt
- gt
- ltxsdschema xmlnsxsd"http//www.w3.org/1999/XMLS
chema"gt - ltxsdannotationgt
- ltxsddocumentationgt
- Proposal Petri Net Markup Language
schema for st-Nets - Matthias Juengel 12.10.2000
- Michael Weber 12.10.2000
- lt/xsddocumentationgt
- lt/xsdannotationgt
- ...
- ...
file//tfs/tools/XMLConv/stNet.xsd
15Example PNML 1.0 ? GTS 1.0 gts.dtd (old
version)
lt!ELEMENT GraphTransformationSystem
(TaggedValue?, ((Types?,Graph,Rule,TaggedValue?
) Module))gt lt!ATTLIST GraphTransformationSystem
name NMTOKEN REQUIREDgt lt!-- Type
Declarations --gt lt!ELEMENT Types
(NodeType,EdgeType)gt lt!ELEMENT NodeType
(TaggedValue?, AttrType, NodeTypeLayout?)gt
lt!-- TaggedValues could be derived attributes,
etc --gt lt!ATTLIST NodeType id ID
REQUIRED name NMTOKEN
REQUIREDgt lt!ELEMENT EdgeType (TaggedValue?,
AttachName, AttrType, EdgeTypeLayout?)gt
lt!-- TaggedValues could be multiplicities,
rolenames, etc.--gt lt!ATTLIST EdgeType
id ID REQUIRED name
NMTOKEN REQUIRED source IDREFS
IMPLIED target IDREFS IMPLIEDgt
file//tfs/tools/XMLConv/gts.dtd
16Example PNML 1.0 ? GTS 1.0 ProducerConsumerSyst
em.xml
lt?xml version"1.0" encoding"UTF-8"?gt ltpnml
xmlnsxsi"http//www.w3.org/1999/XMLSchema-instan
ce" xsinoNamespaceSchemaLocation"stNet.xsd"gt ltne
t id"n1" type"stNet"gt ltplace id"p1"gt
ltnamegt ltvaluegtready to producelt/valuegt lt/namegt
ltinitialMarkinggt ltvaluegt1lt/valuegt
lt/initialMarkinggt lt/placegt lttransition
id"t1"gt ltnamegt ltvaluegtproducelt/valuegt
lt/namegt lt/transitiongt ltarc id"a1"
source"p1" target"t1"gt ... lt/arcgt ...
p1
a1
t1
file//tfs/tools/XMLConv/ProducerConsumerSystem.x
ml
17Example PNML 1.0 ? GTS 1.0 Stylesheet
pnml2gts.xsl part 1
... ltxsltemplate match"place"gt ltNode
type"IDplace" id"ID_at_id"gt ltAttribute
name"PlaceName" type"IDpn"gt ltattrvalgt
ltxslvariable name"string-value"
select"name/value"/gt ltPrimitiveValue
value"string-value" type"String"
id"IDpnV_at_id"/gt lt/attrvalgt
lt/Attributegt lt/Nodegt ltxslif
test"initialMarking"gt ltNode type"IDtoken"
id"IDTok_at_id"/gt lt/xslifgt lt/xsltemplategt ...
file//tfs/tools/XMLConv/pnml2gts.xsl
18Example PNML 1.0 ? GTS 1.0 Stylesheet
pnml2gts.xsl part 2
... ltxsltemplate match"arc"gt ltxslvariable
name"source" select"_at_source"/gt ltxslvariable
name"target" select"_at_target"/gt ltxslif
test'../transition_at_idsource and
../place_at_idtarget'gt ltEdge
target"IDtarget" source"IDsource"
type"IDarcTP id"ID_at_id"/gt lt/xslifgt
ltxslif test'../place_at_idsource and
../transition_at_idtarget'gt ltEdge
target"IDtarget" source"IDsource"
type"IDarcPT" id"ID_at_id"/gt
lt/xslifgt lt/xsltemplategt ...
file//tfs/tools/XMLConv/pnml2gts.xsl
19Example PNML 1.0 ? GTS 1.0 Outputfile conv.xml
... ltNode id"IDp1" type"IDplace"gt
ltAttribute type"IDpn" name"PlaceName"gt
ltattrvalgt ltPrimitiveValue
id"IDpnVp1" type"String" value"ready to
produce"/gt lt/attrvalgt
lt/Attributegt lt/Nodegt ... ltEdge id"IDa1"
type"IDarcTP" source"IDp1" target"IDt1"/gt ...
file//tfs/tools/XMLConv/conv.xml
20Summary and Outlook
- Universal XML Converting Tool tfs/tools/XMLConv
- Outlook
- Creating an universal PNML / GTS tool working in
both directions - Improving GenGEd to import / export all types of
Petri-Nets in GTS-Format - Animation of Petri-Nets in GenGEd