Converting XMLFiles with XSLT and XPath - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Converting XMLFiles with XSLT and XPath

Description:

XSLT: eXtensible Stylesheet Language Transformations ... Transformation Factory. new feature in version 1.1. XML Inputfile ... Animation of Petri-Nets in GenGEd ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 21
Provided by: tfsCsTu
Category:

less

Transcript and Presenter's Notes

Title: Converting XMLFiles with XSLT and XPath


1
Converting XML-Files with XSLT and XPath
XSLT eXtensible Stylesheet Language
Transformations Version 1.0 XPath eXtensible
Path Language Version 1.0
  • Karsten Ehrig

PetriNet-AG GraGra-AG 2001
2
Outline 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

3
Motivation
  • 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
4
XML 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
5
XML 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
6
XML 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
7
XSL (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
8
Features 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
9
Features 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
10
Converting 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
...
11
Example 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
12
Java 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 / ...

13
Example 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

14
Example 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
15
Example 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
16
Example 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
17
Example 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
18
Example 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
19
Example 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
20
Summary 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
Write a Comment
User Comments (0)
About PowerShow.com