1
COMP60411 Semi-structured Data and the Web Datatypes Relax NG, XML Schema, and Tree Grammars XSLT
Bijan Parsia and Uli Sattler
University of Manchester
1 Sunday, 21 October 2012
COMP60411 Semi-structured Data and the Web Datatypes Relax NG, XML - - PowerPoint PPT Presentation
COMP60411 Semi-structured Data and the Web Datatypes Relax NG, XML Schema, and Tree Grammars XSLT Bijan Parsia and Uli Sattler University of Manchester 1 Sunday, 21 October 2012 1 Datatypes and representations Or, are you my type? 2
1
1 Sunday, 21 October 2012
2 2 Sunday, 21 October 2012
3 3 Sunday, 21 October 2012
4 4 Sunday, 21 October 2012
– Did it fail silently.
– Will anything else break?
5 5 Sunday, 21 October 2012
6 6 Sunday, 21 October 2012
7 7 Sunday, 21 October 2012
– integers rather than strings – elements have types as well as names
– Derviation by extension
8 8 Sunday, 21 October 2012
9 9 Sunday, 21 October 2012
10 10 Sunday, 21 October 2012
– if (true()) then 1+1 else "2" – What is itʼs type? – if (true()) then 1+1 else "2" instance of xs:integer
– if (false()) then 1+1 else "2"
– (if (false()) then 1+1 else "2") instance of xs:string
– if ($aBool) then 1+1 else "2"
– (if ($aBool) then 1+1 else "2") instance of (xs:integer | xs:string)
11 11 Sunday, 21 October 2012
– "2" + 2 – Arithmetic operator is not defined for arguments of types (xs:integer, xs:string)
– (if (false()) then 1+1 else "2") + 2
– declare function ssd:test($x as xs:boolean) as xs:integer{ if ($x) then 1+1 else "2" + 2 }; – declare function ssd:test($x as xs:boolean) as xs:integer{ if ($x) then 1+1 else "2" }; My checker doesn’t flag this error It does flag this one!
12 12 Sunday, 21 October 2012
– Same as: ((1.0 cast as xs:double l) + 125E2) instance of xs:double
– Required item type of value in 'treat as' expression is xs:decimal
– (1 treat as xs:integer) vs. (1 treat as xs:decimal) » Fixes the static type
– This results in 1
13
13 Sunday, 21 October 2012
http://msdn.microsoft.com/en-us/library/ms191231.aspx 14 14 Sunday, 21 October 2012
– import schema default element namespace "…” at "el-typed.xsd"; <instance-of> <constant name="sally"/> <atomic name="Person"/> </instance-of>/element(*, ClassExpression)
– import schema default element namespace "..." at "el-typed.xsd"; validate {<instance-of> <constant name="sally"/> <atomic name="Person"/> </instance-of>}/element(*, ClassExpression)
15 15 Sunday, 21 October 2012
import schema namespace el="http://owl.cs.manchester.ac.uk/2010/comp/ssd-60372/day2/el" at "el-typed.xsd"; import schema namespace owl="http://www.w3.org/2002/07/owl#" at "owl2-xml.xsd"; declare namespace ex="http://ex.org"; declare function ex:convertAxiom($ax as element(*, el:Axiom)) as element(*, owl:Axiom){ typeswitch ($ax) case schema-element(el:equivalent) return validate{<owl:EquivalentClasses>{ for $expr in $ax/* return ex:convertExpression($expr)}</owl:EquivalentClasses>} default return validate {<owl:EquivalentClasses><owl:Class IRI="http://BOGUS"/><owl:Class IRI="http://BOGUS"/></
}; declare function ex:convertExpression($expr as element(*, el:ClassExpression)) as element(*,
if ($expr instance of element(el:atomic)) then validate{<owl:Class IRI="{$expr/@name}"/>} else validate {<owl:Class IRI="http://BOGUS"/>} (:These would be easier if the elements were nilable:) }; declare function ex:convert($ont as element(*, el:Ontology)) as element(owl:Ontology, owl:Ontology){ validate{ <owl:Ontology> {for $e in $ont/element(*,el:Axiom) return ex:convertAxiom($e)} </owl:Ontology> } }; ex:convert(validate{doc("el1.xml")/*}) 16 16 Sunday, 21 October 2012
<?xml version="1.0" encoding="UTF-8"?> <owl:Ontology xmlns:owl="http://www.w3.org/2002/07/owl#"> <owl:EquivalentClasses> <owl:Class IRI="http://BOGUS"/> <owl:Class IRI="http://BOGUS"/> </owl:EquivalentClasses> <owl:EquivalentClasses> <owl:Class IRI="http://BOGUS"/> <owl:Class IRI="http://BOGUS"/> </owl:EquivalentClasses> <owl:EquivalentClasses> <owl:Class IRI="Person"/> <owl:Class IRI="http://BOGUS"/> </owl:EquivalentClasses> <owl:EquivalentClasses> <owl:Class IRI="http://BOGUS"/> <owl:Class IRI="http://BOGUS"/> </owl:EquivalentClasses> </owl:Ontology>
17 17 Sunday, 21 October 2012
http://www.informit.com/articles/article.aspx?p=100667&seqNum=6 18 18 Sunday, 21 October 2012
“Location” doesn’t really matter
19 19 Sunday, 21 October 2012
– (Each “digit” is a bit not a character)
*We consider only ints, i.e., 32 bit integers ** http://www.javaworld.com/javaworld/javatips/jw-javatip130.html?page=2 ** See also: http://lingpipe-blog.com/2010/06/22/the-unbearable-heaviness-jav-strings/
20 20 Sunday, 21 October 2012
http://download.oracle.com/javase/6/docs/api/java/lang/Integer.html
21 21 Sunday, 21 October 2012
– Ordered lists with random access – [1, 2, “one”, “two”]
– Associative arrays/dictionary – {“one”:1, “two”:2}
– [{“one”:1, “o1”:{“a1”: [1,2,3.0], “a2”:[]}]
*Strings can be thought of as a composite, i.e., an array of characters, but not here.
22 22 Sunday, 21 October 2012
{"menu": { "id": "file", "value": "File", "popup": { "menuitem": [ {"value": "New", "onclick": "CreateNewDoc()"}, {"value": "Open", "onclick": "OpenDoc()"}, {"value": "Close", "onclick": "CloseDoc()"} ] } }} <menu id="file" value="File"> <popup> <menuitem value="New" onclick="CreateNewDoc()" /> <menuitem value="Open" onclick="OpenDoc()" /> <menuitem value="Close" onclick="CloseDoc()" /> </popup> </menu> http://www.json.org/example.html
23 23 Sunday, 21 October 2012
{"menu": [{ "id": "file", "value": "File"}, "popup": [ "menuitem": {"value": "New", "onclick": "CreateNewDoc()"}, "menuitem": {"value": "Open", "onclick": "OpenDoc()"}, "menuitem": {"value": "Close", "onclick": "CloseDoc()"} ] ] }} <menu id="file" value="File"> <popup> <menuitem value="New" onclick="CreateNewDoc()" /> <menuitem value="Open" onclick="OpenDoc()" /> <menuitem value="Close" onclick="CloseDoc()" /> </popup> </menu> http://www.json.org/example.html
24 24 Sunday, 21 October 2012
{"menu": [{"id": "file", "value": "File"}, [{"popup": [{}, [{"menuitem": [{"value": "New", "onclick": "CreateNewDoc()"},[]]}, {"menuitem": [{"value": "Open", "onclick": "OpenDoc()"},[]]}, {"menuitem": [{"value": "Close", "onclick": "CloseDoc()"},[]]} ] ] } ] ] } <menu id="file" value="File"> <popup> <menuitem value="New" onclick="CreateNewDoc()" /> <menuitem value="Open" onclick="OpenDoc()" /> <menuitem value="Close" onclick="CloseDoc()" /> </popup> </menu> http://www.json.org/example.html 25 25 Sunday, 21 October 2012
26 26 Sunday, 21 October 2012
27 27 Sunday, 21 October 2012
– Which? – When is ok not to preserve?
28 28 Sunday, 21 October 2012
29
29 Sunday, 21 October 2012
30
30 Sunday, 21 October 2012
31
31 Sunday, 21 October 2012
<configuration xmlns="http://saxon.sf.net/ns/configuration" edition="EE"> <serialization method="xml" /> </configuration>
element configuration { attribute edition {"ee"}, element serialization {attribute method {"xml"}}}
32
32 Sunday, 21 October 2012
33
33 Sunday, 21 October 2012
34
34 Sunday, 21 October 2012
35
– <foo>one 2 3</foo>
– Content is {“one”, 2, “3”}
35 Sunday, 21 October 2012
36
36 Sunday, 21 October 2012
37 37 Sunday, 21 October 2012
38
– for each w ∈ nodes(T) with children w1 w2... wn, there exists a rule X → a e ∈ P such that
r(w1) = FEd r(w2) =SEd r(wn) =SEd
– are central to tree grammars – reflect element declarations
38 Sunday, 21 October 2012
39 39 Sunday, 21 October 2012
<!ELEMENT T (N1,N2*)> <!ELEMENT N1 (M|(M,M))> <!ELEMENT N2 (#PCDATA)> <!ELEMENT M (#PCDATA)> F = (N, Σ, S, P) with N = {T, N1, N2, M, pcdata} Σ = {T, N1, N2, M, pcdata} S = {T} P = { T → T (N1,N2*), N1 → N1 (M|(M,M)), N2 → N2 pcdata, M → M pcdata, pcdata → pcdata ε}
pcdata
40 40 Sunday, 21 October 2012
– [DTD] determistic (or 1-unambiguous), e.g., (M|(M,M)) is not deterministic, (M,(M|ε)) is. e.g., ((b, c) | (b, d)) is not deterministic, b,(c|d) is. From http://www.w3.org/TR/REC-xml/:
41
More formally: a finite state automaton may be constructed from the content model using the standard algorithms, e.g. algorithm 3.5 in section 3.9 of Aho, Sethi, and Ullman [Aho/Ullman]. In many such algorithms, a follow set is constructed for each position in the regular expression (i.e., each leaf node in the syntax tree for the regular expression); if any position has a follow set in which more than one following position is labeled with the same element type name, then the content model is in error and may be reported as an error.
41 Sunday, 21 October 2012
– and not because their content model is deterministic! – they are single-type even with non-deterministic content model
42 42 Sunday, 21 October 2012
✓ types (complex and anonymous)
43 43 Sunday, 21 October 2012
– <xs:element name="mylist" type="BlistT"></xs:element>
– MYLIST → mylist BLIST^TYPE – add MYLIST, BLIST^TYPE to non-terminals, add mylist to terminals
– <xs:element name="mylist">
<xs:complexType> <xs:sequence> <xs:element name="ename" type="CompT" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element>
– MYLIST → mylist ENAME,ENAME* – ENAME → ename COMP^TYPE – add MYLIST, ENAME, COMP^TYPE to non-terminals, add mylist, ename to terminals what is the default for minOccurs?
44 44 Sunday, 21 October 2012
– <xs:complexType name="BlistT"> <xs:sequence> <xs:element name="friend" type='PersonT' minOccurs = ʻ1ʼ maxOccurs ='2'/> </xs:sequence> </xs:complexType>
– BLIST^TYPE → (FRIEND | (FRIEND,FRIEND)) – FRIEND → friend PERSON^TYPE – add BLIST^TYPE, FRIEND, PERSON^TYPE to non-terminals, add friend to terminals
38
%% generalized rule: to be expanded!
45 45 Sunday, 21 October 2012
<xs:choice> <xs:sequence> <xs:element name="A" type="xs:string"/> <xs:element name="B" type="xs:string"/> </xs:sequence> <xs:sequence> <xs:element name="A" type="xs:string"/> <xs:element name="C" type="xs:string"/> </xs:sequence> </xs:choice> </xs:complexType>
– BBLIST^TYPE → (A,B) | (A,C) – A → A STRING^TYPE – B → B STRING^TYPE – C → C STRING^TYPE – add BBLIST^TYPE, A, B, C, STRING^TYPE to non-terminals, add A, B, C to terminals %% generalized rule -- to be expanded! %% UPA - violation: %% Oxygen complains!
46 46 Sunday, 21 October 2012
– AT^TYPE → N*, BT^TYPE → N* – N → N ??LIST^TYPE
– AT^TYPE → N^AS^ALIST^TYPE* BT^TYPE → N^AS^BLIST^TYPE* – N^AS^ALIST^TYPE → N ALIST^TYPE – N^AS^BLIST^TYPE → N BLIST^TYPE
<xs:complexType name="AT"> <xs:sequence> <xs:element name="N" type="AlistT" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="BT"> <xs:sequence> <xs:element name="N" type="BlistT" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType>
47 47 Sunday, 21 October 2012
– e.g., BLIST^TYPE → (FRIEND | (FRIEND,FRIEND))
– MYLIST → mylist (FRIEND | (FRIEND,FRIEND))
– YOURLIST → yourlist BLIST^TYPE and thus
– YOURLIST → yourlist (FRIEND | (FRIEND,FRIEND)) pick illegal rule X → e: – remove X → e from rule set – replace all occurrences of X in rule set with e until no illegal rules are left in rule set
48 48 Sunday, 21 October 2012
<xs:complexType name="NT"> <xs:choice> <xs:element name="test2" type="AT"/> <xs:element name="EndElement" type="xs:string"/> </xs:choice> </xs:complexType> <xs:complexType name="AT"> <xs:choice> <xs:element name="test1" type="NT"/> <xs:element name="EndElement" type="xs:string"/> </xs:choice> </xs:complexType>
NT^TYPE → (TEST2 | ENDELEMENT) TEST2 → test2 AT^TYPE ENDELEMENT → EndElement STRING^TYPE AT^TYPE → (TEST1 | ENDELEMENT) TEST1 → test1 NT^TYPE ENDELEMENT → EndElement STRING^TYPE TEST2 → test2 (TEST1 | ENDELEMENT) ENDELEMENT → EndElement STRING^TYPE TEST1 → test1 (TEST2 | ENDELEMENT) ENDELEMENT → EndElement STRING^TYPE
49 49 Sunday, 21 October 2012
– they are tree grammars – are they single-type? – are they local?
– N^AS^ALIST^TYPE → N ALIST^TYPE – N^AS^BLIST^TYPE → N BLIST^TYPE – .. N^AS^ALIST^TYPE and N^AS^BLIST^TYPE are competing!
50 50 Sunday, 21 October 2012
– This is ensured by the Unique Particle Attribution constraint in WXS.
N = {Book, PA, Editor, A, Paper, F, L} Σ = {B,N,A,P,C} S = {Book, Paper} P = { Book → B Editor|PA, Paper → P PA, Editor → N F,L, PA → N L,A, F → F ε, L → L ε, A → A ε }
51 Sunday, 21 October 2012
– to make validation easier & for compatibility with SGML – e.g., through Unique Particle Attribute Constraint:
52
A content model must be formed such that during validation of an element information item sequence, the particle component contained directly, indirectly or implicitly therein with which to attempt to validate each item in the sequence in turn can be uniquely determined without examining the content or attributes of that item, and without any information about the items in the remainder of the sequence.
http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#cos-nonambig
Rephrasing: a content model M must be formed such that, during validation of an element E’s childnode sequence E1...Ek, we can, starting from i = 1 and increasing, associate each Ei with a single particle contained (possibly implicitly) in M without examining the content or attributes of Ei, and without any information about any Ej with j >i.
52 Sunday, 21 October 2012
– an element of a type X derived by restriction or extension from Y can be used in place of an element of type Y
– we call this ‘named’ typing:
(by comparing structure)
– in DTDs, we don’t have types!
<xs:complexType> <xs:sequence> <xs:element name="person" type= "NewPersonType" minOccurs="0" maxOccurs="1"/> <xs:element name="person" type= "OldPersonType" minOccurs="0" maxOccurs="1"/> </xs:sequence> </xs:complexType> 53 <person phone="2"> <Name>Peter</Name> <DoB>1966-05-04</DoB></person> <person xsi:type="LongPersonType" phone="5432"> <Name>Paul</Name> <DoB>1967-05-04</DoB> <address>Manchester</address></person> 53 Sunday, 21 October 2012
54
54 Sunday, 21 October 2012
55 55 Sunday, 21 October 2012
56
– no default attributes – no entity declarations – no key/uniqueness constraints – minimal datatypes: only “token” and “string” like DTDs (but a mechanism to use XSD datatypes)
– it’s (claimed to be) easy to use – it doesn’t have complex constraints on description of element content like determinism/1-unambiguity – it’s claimed to be reliable – but you need other tools to do other things (like datatypes and attributes)
56 Sunday, 21 October 2012
57
– [DTD] deterministic (and thus look-ahead-free) – [WXS] deterministic (EDC, every matching child node sequence matches in exactly one way only) – [WXS] UPA constraint expresses both and other constraints even more
– some tools annotate a (valid) document while parsing:
– if your schema is not single-type, then
PSVIs
57 Sunday, 21 October 2012
58
Reasons why one would want to validate an XML document:
– postcode correctness – VAT/tax/other numeric constraints – spell checking
...only few of these checks can be carried out by validating against schemas... Relax NG was designed to
58 Sunday, 21 October 2012
59
– a pattern is a description of a set of valid node sets – we can view our example as different combinations
design patterns for each – enhanced flexibility
<?xml version="1.0" encoding="UTF-8"?> <people> <person age="41"> <name> <first>Harry</first> <last>Potter</last> </name> <address>4 Main Road </address> <project type="epsrc" id="1"> DeCompO </project> <project type="eu" id="3"> TONES </project> </person> <person>.... </people>
59 Sunday, 21 October 2012
60
Relax NG comes in 2 syntaxes
– succinct – human readable
– verbose – machine readable
ü Trang converts between the two, pfew! (and also into/from
languages) ü Trang can be used from Oxygen grammar { start = element name { element first { text }, element last { text } }} <grammar xmlns="http:...” xmlns:a="http:.." datatypeLibrary="http:...> <start> <element name="name"> <element name="first"><text/></element> <element name="first"><text/></element> </element> </start> </grammar>
60 Sunday, 21 October 2012
61
– text – attribute – element
–
– unordered groups – choices
– can be marked as “data” and linked
<?xml version="1.0" encoding="UTF-8"?> <people> <person age="41"> <name> <first>Harry</first> <last>Potter</last> </name> <address>4 Main Road </address> <project type="epsrc" id="1"> DeCompO </project> <project type="eu" id="3"> TONES </project> </person> <person>.... </people>
element name { element first { text }, element last { text }}
is a RelaxNG schema for (parts of) this:
61 Sunday, 21 October 2012
62
<?xml version="1.0" encoding="UTF-8"?> <people> <person age="41"> <name> <first>Harry</first> <last>Potter</last> </name> <address>4 Main Road </address> <project type="epsrc" id="1"> DeCompO </project> <project type="eu" id="3"> TONES </project> </person> <person>.... </people> use “?” if
grammar { start = element people {people-content} people-content = element person { person-content }+ person-content = attribute age { text },
name-content = element first { text },
project-content = attribute type { text },
is a RelaxNG schema for this
62 Sunday, 21 October 2012
<?xml version="1.0" encoding="UTF-8"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0"> <start> <element name="people"> <ref name="people-content"/> </element> </start> <define name="people-content"> <oneOrMore> <element name="person"> <ref name="person-content"/> </element> </oneOrMore> </define> <define name="person-content"> <attribute name="age"/> <element name="name"> <ref name="name-content"/> </element> <oneOrMore> <element name="address"> <text/> </element> </oneOrMore> <zeroOrMore> <element name="project"> <ref name="project-content"/> </element> </zeroOrMore> </define> <define name="name-content"> <element name="first"> <text/> </element> <optional> <element name="middle"> <text/> </element>
63 grammar { start = element people {people-content} people-content = element person { person-content }+ person-content = attribute age { text },
name-content = element first { text },
project-content = attribute type { text },
use Trang to convert ⇆
63 Sunday, 21 October 2012
64
grammar { start = people-element people-element = element people { person-element+ } person-element = element person {
name-element = element name {
address-element = element address { text } project-element = element project {
grammar { start = element people {people-content} people-content = element person { person-content }+ person-content = attribute age { text },
name-content = element first { text },
project-content = attribute type { text },
64 Sunday, 21 October 2012
65
grammar {start = element people {people-content} people-content = element person { person-content }+ person-content = HR-stuff,
HR-stuff = attribute age { text },
contact-stuff = attribute phone { text },
name-content = element first { text },
project-content = element project { attribute type { text },
<?xml version="1.0" encoding="UTF-8"?> <people> <person age="41"> <name> <first>Harry</first> <last>Potter</last> </name> <address>4 Main Road </address> <project type="epsrc" id="1"> DeCompO </project> <project type="eu" id="3"> TONES </project> </person> <person>.... </people>
65 Sunday, 21 October 2012
66
– grammar oriented – 2 syntaxes with automatic translation – flexible: we can gather different aspects of elements into different patterns – unconstrained: no constraints regarding unambiguity/1-ambiguity/deterministic content model/Unique Particle Constraints/Element Declarations Consistent – like for XSD, we have an “ALL” construct for unordered groups, “interleave” &: element person { attribute age { text}, attribute phone { text}, name-element , address-element+ , project-element*} here, the patterns must appear in the specified order, (except for attributes, which are allowed to appear in any order in the start tag): here, the patterns can appear any order: element person { attribute age { text } & attribute phone { text} & name-element & address-element+ & project-element*}
66 Sunday, 21 October 2012
67 grammar { start = AddressBook AddressBook = element addressBook { Card* } Card = element card { Inline } Inline = Name, Email+ Name = element name { text } Email = element email { text } }
Translate into G=(N, Σ, S, P) with N = {AddressBook, Card, Inline, Name, Email, Pcdata} Σ = {addressBook, card, name, email, pcdata} S = {AddressBook} P = {AddressBook → addressBook Card*, Card → card Inline, Inline → Name, Email+, Name → name Pcdata, Email → email Pcdata, Pcdata → pcdata ϵ }
67 Sunday, 21 October 2012
68
grammar { start = p-el p-el = element people { per-el+ } per-el = element person { attribute age { text }, na-el, ad-el+, pro-el*} na-el = element name { element first { text }, element middle { text }?, element last { text } } ad-el = element address { text } pro-el = element project { attribute type { text }, attribute id {text}, text }} Translate into G = (N, Σ, S, P) with N = {P-EL, PER-EL, NA-EL, AD-EL, PRO-EL, FIRST, MIDDLE, LAST, Pcdata} Σ = {people, person, name, first, middle, last, address, project} S = {P-EL} P = {P-EL → people PER-EL, PER-EL*, PER-EL → person NA-EL,AD-EL, AD-EL*,PRO-EL* NA-EL → name FIRST, (MIDDLE|ε), LAST, FIRST → first Pcdata, MIDDLE → middle Pcdata, LAST → last Pcdata, AD-EL → address Pcdata, PRO-EL → project Pcdata, Pcdata → pcdata ϵ }
68 Sunday, 21 October 2012
69
grammar { start = element people {people-content} people-content = element person { person-content }+ person-content = attribute age { text }, element name {name-content}, element address { text }+, element project {project-content}* name-content = element first { text }, element middle { text }?, element last { text } project-content = attribute type { text }, attribute id {text}, text } Translate into G=(N, Σ, S, P) with N = {PEOPLE, P-C, PER-C, NA, NA-C, PERSON, PRO-C,ADR, PROJ, PRO-C, FIRST, MIDDLE,LAST, Pcdata} Σ = {people, person, name, first, middle, last, address, project} S = {PEOPLE} P = {PEOPLE → people P-C, P-C → PERSON, PERSON*, PERSON → person PER-C, PER-C → NA, ADR, ADR*,PROJ, NA → name NA-C, ADR → address Pcdata, PROJ → project PRO-C, PRO-C → pcdata ϵ, NA-C → FIRST,(MIDDLE|ϵ),LAST FIRST → first Pcdata, MIDDLE → middle Pcdata, LAST → last Pcdata, Pcdata → pcdata ϵ }
Ignore! Ignore! expand! expand!
This Relax NG style makes translation of rules less easy… and leads to generalized rules!
69 Sunday, 21 October 2012
70 ... people-content = element person { person-content }+ ..... person-content = attribute age { text }, element name {name-content}, element address { text }+, element project {project-content}*
... PERSON → person PER-C, PER-C → NA, ADR, ADR*,PROJ, NA → name NA-C, ADR → address Pcdata, ...
expand!
for each illegal rule X → e: – remove X → e from rule set – replace all occurrences of X in rule set with e
70 Sunday, 21 October 2012
... P-C → PERSON, PERSON*,FRIEND,FRIEND* PERSON → person PER-C, FRIEND → friend FRIE-C, PER-C → NA^NA-C, ... FRIE-C → NA^FRIE-NA-C, ... NA^NA-C → name NA-C, NA^FRIE-NA-C → name FRIE-NA-C, ...
... people-content = element person { person-content }+, element friend {friend-content }+ ..... person-content = attribute age { text }, element name {name-content}, ... friend-content = attribute age { text }, element name {friend-name-content}, ...
71
71 Sunday, 21 October 2012
– local? no: example on previous slide leads to competing non-terminals (NA^PER-C and NA^FRIE-C) – single-type? no: see example below NA^NA-C and NA^FO-NA-C compete and occur in the same RHS – so is Relax NG as powerful as tree grammars?
72
... NA^PER-C → name NA-C, NA^FRIE-C → name NA-C, ...
... person-content = attribute age { text }, element name {name-content} | element name {foreign-name-content}, ...
... PER-C → NA^NA-C | NA^FO-NA-C NA^NA-C → name NA-C, NA^FO-NA-C → name FO-NA-C, ... 72 Sunday, 21 October 2012
(fortunately, the tree grammar regular expression syntax is very close to and more strict than Relax NG regular expression syntax)
a grammar, where N1 , ... , Nk are all start symbols, i.e., S = {N1 , ... , Nk}
73
N = element t { regexp } grammar {start = N1 | ... | Nk ..... }
73 Sunday, 21 October 2012
74
with our knowledge
74 Sunday, 21 October 2012
75
75 Sunday, 21 October 2012
76 76 Sunday, 21 October 2012
– the problem of – algorithms for
77
algorithm Tree T Grammar G “yes”, if T ∈ L(G) “no”, otherwise See the paper by Murata, Lee, Mani, Kawaguchi
77 Sunday, 21 October 2012
(this gives us automatically a validator for structural aspect of DTDs)
(this gives us automatically a validator for structural aspect of WXS)
– we also assume that we have a subroutine – to see how to build that one (it’s based on a translation of regular expressions into finite state machines (aka automata)), consult
78
ValAlgo Tree T Grammar G “yes”, if T ∈ L(G) “no”, otherwise MatchAlgo String w regular expression e “yes”, if w ∈ L(e), (w matches e) “no”, otherwise
78 Sunday, 21 October 2012
79
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
79 Sunday, 21 October 2012
– down, we push relevant information for this node on stacks – up, we pop relevant information for this node from stacks
80
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
80 Sunday, 21 October 2012
Input: DOM Tree for T, local tree grammar G = (N, Σ, S, P), NT is a stack of strings of non-terminals R is a stack of production rules Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down,
if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop
When an element E is visited on way up,
pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals out of NT and push w’N onto NT else report “not accepted” and stop
report “accepted” and stop
81
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
See the paper by Murata, Lee, Mani, Kawaguchi
store rule for E’s content in R start remembering E’s child nodes retrieve rule for E’s content in R retrieve E’s child nodes add E’s terminal node to its predecessor siblings to store NTs of child nodes 81 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
82
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
82 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
83 15
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
83 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
84
B → b (C,C)|C S → a B,B* ϵ ϵ
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
84 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
85
C → c ϵ|C B → b (C,C)|C S → a B,B* ϵ ϵ ϵ
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
85 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
86
B → b (C,C)|C S → a B,B* ϵ ϵ C → c ϵ|C
yes, ϵ ∈ L(ϵ|C)
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
86 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
87
B → b (C,C)|C S → a B,B* C ϵ C → c ϵ|C
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
87 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
88
C ϵ C → c ϵ|C B → b (C,C)|C S → a B,B* ϵ ϵ
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
88 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
89
C ϵ B → b (C,C)|C S → a B,B* ϵ C → c ϵ|C
yes, ϵ ∈ L(ϵ|C)
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
89 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
90
B → b (C,C)|C S → a B,B* CC ϵ C → c ϵ|C
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
90 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
91
S → a B,B* ϵ B → b (C,C)|C
yes, CC ∈ L((C,C)|C)
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
91 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
92
S → a B,B* B
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
92 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
93
B → b (C,C)|C S → a B,B* ϵ B
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
93 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
94
C → c ϵ|C B → b (C,C)|C S → a B,B* ϵ ϵ B
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
94 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
95
B → b (C,C)|C S → a B,B* ϵ B C → c ϵ|C
yes, ϵ ∈ L(ϵ|C)
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
95 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
96
B → b (C,C)|C S → a B,B* C B C → c ϵ|C
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
96 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
97
S → a B,B* B B → b (C,C)|C
yes, C ∈ L((C,C)|C)
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
97 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
98
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
S → a B,B* BB B → b (C,C)|C ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
98 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
99
S → a B,B* yes, BB ∈ L(B,B*)
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
99 Sunday, 21 October 2012
– G = ({S,B,C},{a,b,c},{S},P) with P = { S → a B,B*, B → b (C,C)|C, C → c ϵ|C}
100
“accepted” (“yes”), T ∈ L(G)
Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, if there is a production rule N → a e in P with a = E’s tag name then push N → a e onto R and push ϵ onto NT else report “not accepted” and stop When an element E is visited on way up, pop a rule N → a e out of R pop a string of non-terminals w out of NT if w matches e then pop a string w’ of non-terminals
else report “not accepted” and stop report “accepted” and stop
ValAlgo XML doc/Tree T local Grammar G “yes”, if T ∈ L(G) “no”, otherwise
100 Sunday, 21 October 2012
– walk the DOM tree in a depth-first, left-2-right way, or – use a SAX parser and do it in a streaming fashion
– single-type tree grammars (and WXS)
contains competing non-terminals
node
– general tree grammars (and Relax NG)...
101 101 Sunday, 21 October 2012
102
102 Sunday, 21 October 2012
103
103 Sunday, 21 October 2012
104
from: http://www.w3.org/TR/xslt
104 Sunday, 21 October 2012
105
105 Sunday, 21 October 2012
106
106 Sunday, 21 October 2012
<xs:complexType name="Person">)
107
107 Sunday, 21 October 2012
108
108 Sunday, 21 October 2012
109
Alternatively: <xsl:transform version="1.0” xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/ xmlns:mine=“...”> top-level-elements </xsl:transform>
xsl:import xsl:include xsl:strip-space xsl:preserve-space xsl:output xsl:key xsl:decimal-format xsl:namespace-alias xsl:attribute-set xsl:variable xsl:param xsl:template
later and in more detail
109 Sunday, 21 October 2012
110
– results in the union of the documents – origin of declarations has no effect on their priority
– like xsl:include, but local declarations are “stronger” than imported ones – can only occur as child nodes of the root element & before other elements
– to specify element names for which white space should be removed/ preserved – preserving white space is default – e.g., <xsl:strip-space elements="year city country"/> <xsl:preserve-space elements=”name title description" />
– to declare a named key to be used in the style sheet with the key() function – note: the key does not have to be unique!
110 Sunday, 21 October 2012
111
111 Sunday, 21 October 2012
112
– with some restrictions,e.g., it must evaluate to a node set – for XSLT 1.0, use XPath 1.0, – for XSLT 2.0, use XPath 2.0,
– including instructions such as xsl:apply-templates or xsl:copy-of
the pattern the template
112 Sunday, 21 October 2012
113
<xsl:template match=expression name = qname priority = number mode = qname> parameter-list template-def </xsl:template>
<xsl:template match="emph"> <fo:inline-sequence font-weight="bold"> <xsl:apply-templates/> </fo:inline-sequence> </xsl:template> <fo:inline-sequence font-weight="bold"> important </fo:inline-sequence>
yields
113 Sunday, 21 October 2012
114
– thus we always have a context node
– match the context node and – have highest priority
<xsl:template match="emph"> <fo:inline-sequence font-weight="bold"> <xsl:apply-templates/> </fo:inline-sequence> </xsl:template>
114 Sunday, 21 October 2012
115
<?xml .... ?> root people person person name age=41 address
Potter 4 Main Road Harry
first last
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="my.xsl"?> <people> <person age="41"> <name> <first>Harry</first> <last>Potter</last> </name> <address>4 Main Road </address> </person> <person age="43"> <name> <first>Tony</first> <last>Potter</last> </name> <address>4 Main Road </address> </person> </people>
<?xml .... ?>
115 Sunday, 21 October 2012
116
<?xml .... ?> root people person person name age=41address
Potter 4 Main Road Harry
first last
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> </xsl:stylesheet>
116 Sunday, 21 October 2012
117
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="*|/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="text()|@*"> <xsl:value-of select="."/> </xsl:template> <xsl:template match="processing-instruction()|comment()"/> </xsl:stylesheet>
(1) for all element & document nodes (3) for all text and attribute nodes (2) don’t do anything but apply templates to all child nodes (4) return their value (5) ignore p-i & comments
117 Sunday, 21 October 2012
118
this is the default for “apply-templates”, and node() matches all nodes except attribute nodes & root node
if you want your stylesheet to consider attribute nodes, you must overwrite this default, e.g. like this
(node() matches any node other than an attribute node and the root node)
118 Sunday, 21 October 2012
119
<?xml .... ?> root people person person name age=41address
Potter 4 Main Road Harry
first last
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match= "person"> <xsl:text> Person found! </xsl:text> </xsl:template> </xsl:stylesheet>
119 Sunday, 21 October 2012
120
<?xml .... ?> root people person person name age=41address
Potter 4 Main Road Harry
first last
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match= "person"> Person found called:
</xsl:template> </xsl:stylesheet>
120 Sunday, 21 October 2012
121
<?xml .... ?> root people person person name age=41address
Potter 4 Main Road Harry
first last
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match= "people">
</xsl:stylesheet>
121 Sunday, 21 October 2012
122
<?xml .... ?> root people person person name age=41address
Potter 4 Main Road Harry
first last
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="person"> <myFriend> <xsl:apply-templates select="@*|*|text()"/> </myFriend> </xsl:template> <xsl:template match="@*|text()|*"> <xsl:copy> <xsl:apply-templates select="@*|text()|*"/> </xsl:copy> </xsl:template> <xsl:template match="address"/> </xsl:stylesheet>
122 Sunday, 21 October 2012
123
<?xml .... ?> root people person person name age=41address
Potter 4 Main Road Harry
first last
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="/people"> <html><body><ol> <xsl:apply-templates select="person" mode="o"/> </ol> <xsl:apply-templates select="person" mode="f"/> </body></html> </xsl:template> <xsl:template match="person" mode="o"> <li> <xsl:value-of select="name/first"/> <xsl:value-of select="name/last"/></li> </xsl:template> <xsl:template match="person" mode="f"> <p> Last name: <xsl:value-of select="name/last"/> Age: <xsl:value-of select="age"/> </p> </xsl:template> </xsl:stylesheet>
123 Sunday, 21 October 2012
124
a statement A = <xsl:apply-templates select=location-path mode=mode-name>
– xsl:with-param to pass parameters into template rules – xsl:sort to sort the children before processing (and thereby to be used to sort the output)
evaluated from the current node to select a node set S
– in either document order or in the one given through xsl:sort children
to a node n if – n is in the node set selected by m1 (in addition to being in S) – (in case that mode is used) m2 = mode-name – and it has highest priority (incl. default, order, and explicit priorities)
124 Sunday, 21 October 2012
125
125 Sunday, 21 October 2012
126
126 Sunday, 21 October 2012
127
127 Sunday, 21 October 2012
128
<xsl:template match=”person"> <xsl:element name="Employee"> <xsl:attribute name="alter"> <xsl:value-of select=”@age"/> </xsl:attribute> <xsl:apply-templates/> </xsl:element> </xsl:template>
selected through expression, the string values that corresponds to that node, where the string value of a – text node is its text – attribute node is its value – element or root node is the concatenation of the string values of all its descendent text nodes
128 Sunday, 21 October 2012
129
It can be used to reuse fragments of the source document. Careful: – <xslt:value-of> converts fragments into a string before copying it into the result tree – <xslt:copy-of> copies the complete fragment based on the (required) select attribute, without first converting the fragment into a string – e.g., <xsl:template match="people"> <family><xsl:copy-of select="*"/></family> </xsl:template>
the template (in case it contains a template as child nodes) – namespaces are included automatically in the copy – attributes are not automatically included, they can be included via the “use-attribute-set” attribute
running numbers -- beyond this class <xsl:template match="people"> <family> <xsl:for-each select="person"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:for-each> </family> </xsl:template>
129 Sunday, 21 October 2012
130
<xsl:element name="Employee"> <xsl:if test=”@age > 0"> <xsl:attribute name="alter"> <xsl:value-of select=”@age"/> </xsl:attribute></xsl:if> <xsl:apply-templates/></xsl:element></xsl:template>
130 Sunday, 21 October 2012
131
131 Sunday, 21 October 2012
132
132 Sunday, 21 October 2012