Docstoc

XMLTech

Document Sample
XMLTech Powered By Docstoc
					THE US NATIONAL VIRTUAL OBSERVATORY



             Advanced but ever-so-useful

         XML Technologies:
         Schema, XPath, XQuery, XSL
                an incomplete introduction



                       Ray Plante



                   NVO Summer School 2005 - Aspen   7 September 2005   1
XML Schema
  • What it is:
      – A W3C* standard for defining and verifying an XML grammar
          • An XML Schema document describes…
               – a set of legal XML tags and attributes,
               – what order they go in, and
               – what values are allowed.
          • An XML Schema-aware XML parser can tell you if an XML document follows
            the rules of the grammar
          *World Wide Web Consortium

  • Why you might care:
      – VO uses XML to encode metadata and service messages
      – XML Schema is used to define metadata encoding and message syntax
      – Ability to read XML Schema will help you understand what metadata is
        needed by an app and how to encode it
          • VO end users and many developers will never need to know about Schema
          • Can be helpful for debugging XML documents and messages

  • What you‟ll get from this session:
      – Rudimentary skills for reading an XML Schema document to discern
        the specified XML syntax
      – Understand the role of namespaces in supporting multiple schemas
      – A tool for validating an instance document

                            NVO Summer School 2005 - Aspen   7 September 2005        2
Schema uses XML to describe syntax
                                          http://www.w3.org/TR/xmlschema-0/
  • Contains a list of definitions
     – Elements and types
     – Attributes, groups, attribute-groups


  • Types
     – Simple types: string, integer, dateTime, etc.
         <title>The Astronomy Digital Image Library</title>
         <maxRecords>10000</maxRecords>
         <date role=”completed”>2002-09-30T07:45:00</date>

     – Complex types: contain other elements
     – Defining types
         • Anonymous type – directly inside the definition of an element
         • Global type – “top-level” definition, can be reused




                       NVO Summer School 2005 - Aspen   7 September 2005      3
Namespaces
  • Namespace: a schema‟s unique identifier
    – Set with the targetNamespace attribute
    – Used by an XML document to indicate which schema it is
      compliant with
    – URI format (URL or URN)
  • Using a schema
    – Instance document: XML document that follows the
      grammar defined by the schema
    – xmlns attribute used to identify the default namespace
      that elements belong to
    – Tagging elements with namespace prefixes
       • Prefix defined (anywhere) with xmlns:prefix
           xmlns:res="http://nvoss.org/Resource"
       • Prefixes attached to element/attribute name denotes it
         belongs to the associated schema
           <res:title>…</res:title>

                    NVO Summer School 2005 - Aspen   7 September 2005   4
Validating an instance document

 • A validating parser can test whether an instance
   document is compliant with its schema

 • xsi:schemaLocation attribute tells parser where
   to find Schema document(s)
    – Look-up list made up of namespace-location pairs
          xsi:schemaLocation=”namespace file-or-URL …”


 • xsi:schemaLocation is just a recommendation
    – Parser may have local copies cached for more efficient
      parsing

    validate: a tool for validating XML documents against schemas


                       NVO Summer School 2005 - Aspen   7 September 2005   5
Simple schema
xmltech-simple.xsd
              <?xml version="1.0" encoding="UTF-8"?>
              <xs:schema targetNamespace="http://nvoss.org/VOResource"
                         xmlns:xs="http://www.w3.org/2001/XMLSchema"
                         elementFormDefault="qualified">

                <xs:element name="resource">
                   <xs:complexType>
                      <xs:sequence>

                         <xs:element name="title" type="xs:string" />

                         <xs:element name="referenceURL" type="xs:anyURI"
                                     minOccurs="0"/>

                         <xs:element name="type"
                                     minOccurs="0" maxOccurs="unbounded">
                            <xs:simpleType>
                               <xs:restriction base="xs:string">
                                  <xs:enumeration value="Archive" />
                                  <xs:enumeration value="Catalog" />
                                  <xs:enumeration value="Organisation" />
                               </xs:restriction>
                            </xs:simpleType>
                         </xs:element>

                       </xs:sequence>
                       <xs:attribute name="created" type="xs:dateTime" />
                    </xs:complexType>
                 </xs:element>
              </xs:schema>
                  NVO Summer School 2005 - Aspen   7 September 2005         6
Simple schema
xmltech-simple.xsd
                    <?xml version="1.0" encoding="UTF-8"?>
                    <xs:schema targetNamespace="http://nvoss.org/VOResource"
                               xmlns:xs="http://www.w3.org/2001/XMLSchema"
                               elementFormDefault="qualified">
  targetNamespace
                      <xs:element name="resource">
                         <xs:complexType>
                            <xs:sequence>

                               <xs:element name="title" type="xs:string" />

                               <xs:element name="referenceURL" type="xs:anyURI"
                                           minOccurs="0"/>

                               <xs:element name="type"
                                           minOccurs="0" maxOccurs="unbounded">
                                  <xs:simpleType>
                                     <xs:restriction base="xs:string">
                                        <xs:enumeration value="Archive" />
                                        <xs:enumeration value="Catalog" />
                                        <xs:enumeration value="Organisation" />
                                     </xs:restriction>
                                  </xs:simpleType>
                               </xs:element>

                             </xs:sequence>
                             <xs:attribute name="created" type="xs:dateTime" />
                          </xs:complexType>
                       </xs:element>
                    </xs:schema>
                        NVO Summer School 2005 - Aspen   7 September 2005         7
Simple schema
xmltech-simple.xsd
                           <?xml version="1.0" encoding="UTF-8"?>
                           <xs:schema targetNamespace="http://nvoss.org/VOResource"
                                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                      elementFormDefault="qualified">

                             <xs:element name="resource">
                                <xs:complexType>
                                   <xs:sequence>
   globally-defined
                                      <xs:element name="title" type="xs:string" />
   element
                                      <xs:element name="referenceURL" type="xs:anyURI"
                                                  minOccurs="0"/>
global = Direct child of
   xs:schema                          <xs:element name="type"
                                                  minOccurs="0" maxOccurs="unbounded">
                                         <xs:simpleType>
                                            <xs:restriction base="xs:string">
Only global elements                           <xs:enumeration value="Archive" />
   can serve as a                              <xs:enumeration value="Catalog" />
   document‟s root                             <xs:enumeration value="Organisation" />
                                            </xs:restriction>
   element                               </xs:simpleType>
                                      </xs:element>

                                    </xs:sequence>
                                    <xs:attribute name="created" type="xs:dateTime" />
                                 </xs:complexType>
                              </xs:element>
                           </xs:schema>
                               NVO Summer School 2005 - Aspen   7 September 2005         8
Simple schema
xmltech-simple.xsd
                  <?xml version="1.0" encoding="UTF-8"?>
                  <xs:schema targetNamespace="http://nvoss.org/VOResource"
                             xmlns:xs="http://www.w3.org/2001/XMLSchema"
                             elementFormDefault="qualified">

                    <xs:element name="resource">
                       <xs:complexType>
                          <xs:sequence>
 Anonymous type
                             <xs:element name="title" type="xs:string" />
 definition
                             <xs:element name="referenceURL" type="xs:anyURI"
                                         minOccurs="0"/>

                             <xs:element name="type"
                                         minOccurs="0" maxOccurs="unbounded">
                                <xs:simpleType>
                                   <xs:restriction base="xs:string">
                                      <xs:enumeration value="Archive" />
                                      <xs:enumeration value="Catalog" />
                                      <xs:enumeration value="Organisation" />
                                   </xs:restriction>
                                </xs:simpleType>
                             </xs:element>

                           </xs:sequence>
                           <xs:attribute name="created" type="xs:dateTime" />
                        </xs:complexType>
                     </xs:element>
                  </xs:schema>
                      NVO Summer School 2005 - Aspen   7 September 2005         9
Simple schema
xmltech-simple.xsd
                          <?xml version="1.0" encoding="UTF-8"?>
                          <xs:schema targetNamespace="http://nvoss.org/VOResource"
                                     xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                     elementFormDefault="qualified">

                            <xs:element name="resource">
                               <xs:complexType>
                                  <xs:sequence>
   Content model
                                     <xs:element name="title" type="xs:string" />

                                     <xs:element name="referenceURL" type="xs:anyURI"
                                                 minOccurs="0"/>
sequence: a list of
   elements that must                <xs:element name="type"
                                                 minOccurs="0" maxOccurs="unbounded">
   appear in order                      <xs:simpleType>
                                           <xs:restriction base="xs:string">
                                              <xs:enumeration value="Archive" />
choice: one from a list                       <xs:enumeration value="Catalog" />
   of elements may                            <xs:enumeration value="Organisation" />
                                           </xs:restriction>
   appear                               </xs:simpleType>
                                     </xs:element>

Other models: group,               </xs:sequence>
   all, any                        <xs:attribute name="created" type="xs:dateTime" />
                                </xs:complexType>
                             </xs:element>
                          </xs:schema>
                              NVO Summer School 2005 - Aspen   7 September 2005         10
Simple schema
xmltech-simple.xsd
                        <?xml version="1.0" encoding="UTF-8"?>
                        <xs:schema targetNamespace="http://nvoss.org/VOResource"
                                   xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                   elementFormDefault="qualified">

                          <xs:element name="resource">
                             <xs:complexType>
                                <xs:sequence>

                                   <xs:element name="title" type="xs:string" />
 Locally-defined
 elements                          <xs:element name="referenceURL" type="xs:anyURI"
                                               minOccurs="0"/>

                                   <xs:element name="type"
title: any string                              minOccurs="0" maxOccurs="unbounded">
                                      <xs:simpleType>
                                         <xs:restriction base="xs:string">
referenceURL: URI                           <xs:enumeration value="Archive" />
   format                                   <xs:enumeration value="Catalog" />
                                            <xs:enumeration value="Organisation" />
                                         </xs:restriction>
                                      </xs:simpleType>
type: restricted to a              </xs:element>
   specified list of
   strings                       </xs:sequence>
                                 <xs:attribute name="created" type="xs:dateTime" />
                              </xs:complexType>
                           </xs:element>
                        </xs:schema>
                            NVO Summer School 2005 - Aspen   7 September 2005         11
 Simple schema
 xmltech-simple.xsd
                              <?xml version="1.0" encoding="UTF-8"?>
                              <xs:schema targetNamespace="http://nvoss.org/VOResource"
                                         xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                         elementFormDefault="qualified">

                                <xs:element name="resource">
                                   <xs:complexType>
                                      <xs:sequence>

                                         <xs:element name="title" type="xs:string" />
      Occurance
                                         <xs:element name="referenceURL" type="xs:anyURI"
      restrictions                                   minOccurs="0"/>

                                         <xs:element name="type"
Default:                                             minOccurs="0" maxOccurs="unbounded">
minOccurs=”1” maxOccurs=”1”                 <xs:simpleType>
                                               <xs:restriction base="xs:string">
                                                  <xs:enumeration value="Archive" />
minOccurs=”0”: optional                           <xs:enumeration value="Catalog" />
                                                  <xs:enumeration value="Organisation" />
minOccurs=”1”: required                        </xs:restriction>
                                            </xs:simpleType>
                                         </xs:element>

                                       </xs:sequence>
                                       <xs:attribute name="created" type="xs:dateTime" />
                                    </xs:complexType>
                                 </xs:element>
                              </xs:schema>
                                  NVO Summer School 2005 - Aspen   7 September 2005         12
The compliant instance document
xmltech-simple.xml



          <?xml version="1.0" encoding="UTF-8"?>
          <resource xmlns="http://nvoss.org/VOResource"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://nvoss.org/VOResource
                                        xmltech-simple.xsd" >

             <title>NCSA Astronomy Digital Image Library</title>

             <referenceURL>http://adil.ncsa.uiuc.edu/</referenceURL>

             <type>Archive</type>

          </resource>




              NVO Summer School 2005 - Aspen   7 September 2005             13
The compliant instance document
xmltech-simple.xml



                     <?xml version="1.0" encoding="UTF-8"?>
                     <resource xmlns="http://nvoss.org/VOResource"
 Default namespace             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                               xsi:schemaLocation="http://nvoss.org/VOResource
                                                   xmltech-simple.xsd" >

                        <title>NCSA Astronomy Digital Image Library</title>

                        <referenceURL>http://adil.ncsa.uiuc.edu/</referenceURL>

                        <type>Archive</type>

                     </resource>




                         NVO Summer School 2005 - Aspen   7 September 2005             14
The compliant instance document
xmltech-simple.xml



                        <?xml version="1.0" encoding="UTF-8"?>
                        <resource xmlns="http://nvoss.org/VOResource"
    Default namespace             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                  xsi:schemaLocation="http://nvoss.org/VOResource
                                                      xmltech-simple.xsd" >
xsi namespace
Prefix defined             <title>NCSA Astronomy Digital Image Library</title>

                           <referenceURL>http://adil.ncsa.uiuc.edu/</referenceURL>

                           <type>Archive</type>

                        </resource>




                            NVO Summer School 2005 - Aspen   7 September 2005             15
The compliant instance document
xmltech-simple.xml



                         <?xml version="1.0" encoding="UTF-8"?>
                         <resource xmlns="http://nvoss.org/VOResource"
    Default namespace              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                   xsi:schemaLocation="http://nvoss.org/VOResource
                                                       xmltech-simple.xsd" >
xsi namespace
Prefix defined              <title>NCSA Astronomy Digital Image Library</title>

  xsi:schemaLocation        <referenceURL>http://adil.ncsa.uiuc.edu/</referenceURL>

                            <type>Archive</type>

                         </resource>

xsi:schemaLocation says,
  “Load schema called http://nvoss.org/VOResource
   from local file, xmltech-simple.xsd




                             NVO Summer School 2005 - Aspen   7 September 2005             16
The compliant instance document
xmltech-simple.xml



                         <?xml version="1.0" encoding="UTF-8"?>
                         <resource xmlns="http://nvoss.org/VOResource"
    Default namespace              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                   xsi:schemaLocation="http://nvoss.org/VOResource
                                                       xmltech-simple.xsd" >
xsi namespace
Prefix defined              <title>NCSA Astronomy Digital Image Library</title>

  xsi:schemaLocation        <referenceURL>http://adil.ncsa.uiuc.edu/</referenceURL>

                            <type>Archive</type>

                         </resource>

xsi:schemaLocation says,
  “Load schema called http://nvoss.org/VOResource
   from local file, xmltech-simple.xsd




                             NVO Summer School 2005 - Aspen   7 September 2005             17
Global (Reusable) Types
xmltech-globaltypes.xml
                       <?xml version="1.0" encoding="UTF-8"?>
                       <xs:schema targetNamespace="http://nvoss.org/VOResource"
 Define a prefix for              xmlns:res="http://nvoss.org/VOResource"
 the targetNamespace              xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                  elementFormDefault="qualified">

                          <xs:simpleType name="Type">
                             <xs:restriction base="xs:string">
                                <xs:enumeration value="Archive" />
                                <xs:enumeration value="Catalog" />
                                <xs:enumeration value="Organisation" />
                             </xs:restriction>
                          </xs:simpleType>

                          <xs:complexType name="Resource">
                             <xs:sequence>
                                <xs:element name="title" type="xs:string" />
                                <xs:element name="referenceURL" type="xs:anyURI"
                                            minOccurs="0"/>
                                <xs:element name="type" type="res:Type"
                                            minOccurs="0" maxOccurs="unbounded"/>
                             </xs:sequence>
                             <xs:attribute name="created" type="xs:dateTime" />
                          </xs:complexType>

                          <xs:element name="resource" type="res:Resource" />

                       </xs:schema>

                           NVO Summer School 2005 - Aspen   7 September 2005        18
Global (Reusable) Types
xmltech-globaltypes.xml
                          <?xml version="1.0" encoding="UTF-8"?>
                          <xs:schema targetNamespace="http://nvoss.org/VOResource"
    Define a prefix for              xmlns:res="http://nvoss.org/VOResource"
    the targetNamespace              xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                     elementFormDefault="qualified">
Type defined here…
                             <xs:simpleType name="Type">
                                <xs:restriction base="xs:string">
                                   <xs:enumeration value="Archive" />
                                   <xs:enumeration value="Catalog" />
                                   <xs:enumeration value="Organisation" />
                                </xs:restriction>
                             </xs:simpleType>

                             <xs:complexType name="Resource">
                                <xs:sequence>
                                   <xs:element name="title" type="xs:string" />
                                   <xs:element name="referenceURL" type="xs:anyURI"
                                               minOccurs="0"/>
                                   <xs:element name="type" type="res:Type"
                                               minOccurs="0" maxOccurs="unbounded"/>
                                </xs:sequence>
                                <xs:attribute name="created" type="xs:dateTime" />
                             </xs:complexType>

                             <xs:element name="resource" type="res:Resource" />

                          </xs:schema>

                              NVO Summer School 2005 - Aspen   7 September 2005        19
Global (Reusable) Types
xmltech-globaltypes.xml
                          <?xml version="1.0" encoding="UTF-8"?>
                          <xs:schema targetNamespace="http://nvoss.org/VOResource"
    Define a prefix for              xmlns:res="http://nvoss.org/VOResource"
    the targetNamespace              xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                     elementFormDefault="qualified">
Type defined here…
                             <xs:simpleType name="Type">
                                <xs:restriction base="xs:string">
                                   <xs:enumeration value="Archive" />
                                   <xs:enumeration value="Catalog" />
                                   <xs:enumeration value="Organisation" />
  …and used here                </xs:restriction>
                             </xs:simpleType>

                             <xs:complexType name="Resource">
                                <xs:sequence>
                                   <xs:element name="title" type="xs:string" />
                                   <xs:element name="referenceURL" type="xs:anyURI"
                                               minOccurs="0"/>
                                   <xs:element name="type" type="res:Type"
                                               minOccurs="0" maxOccurs="unbounded"/>
                                </xs:sequence>
                                <xs:attribute name="created" type="xs:dateTime" />
                             </xs:complexType>

                             <xs:element name="resource" type="res:Resource" />

                          </xs:schema>

                              NVO Summer School 2005 - Aspen   7 September 2005        20
Global (Reusable) Elements
xmltech-elrefs.xml
                        <?xml version="1.0" encoding="UTF-8"?>
                        <xs:schema targetNamespace="http://nvoss.org/VOResource"
                                   xmlns:res="http://nvoss.org/VOResource"
                                   xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                   elementFormDefault="qualified">

                           <xs:simpleType name="Type">
                              <xs:restriction base="xs:string">
Element defined here…
                                 <xs:enumeration value="Archive" />
                                 <xs:enumeration value="Catalog" />
                                 <xs:enumeration value="Organisation" />
                              </xs:restriction>
                           </xs:simpleType>

                           <xs:element name="type" type="res:Type"/>

                           <xs:complexType name="Resource">
                              <xs:sequence>
   …and used here                <xs:element name="title" type="xs:string" />
                                 <xs:element name="referenceURL" type="xs:anyURI"
                                             minOccurs="0"/>
                                 <xs:element ref="res:type"
                                             minOccurs="0" maxOccurs="unbounded"/>
                              </xs:sequence>
                              <xs:attribute name="created" type="xs:dateTime" />
                           </xs:complexType>

                           <xs:element name="resource" type="res:Resource" />

                        </xs:schema>

                            NVO Summer School 2005 - Aspen   7 September 2005        21
Schema Documentation
         <?xml version="1.0" encoding="UTF-8"?>
         <xs:schema targetNamespace="http://nvoss.org/VOResource"
                    xmlns:res="http://nvoss.org/VOResource"
                    xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    elementFormDefault="qualified">

            <xs:simpleType name="Type">
               <xs:restriction base="xs:string">
                  <xs:enumeration value="Archive" />
                  <xs:enumeration value="Catalog" />
                  <xs:enumeration value="Organisation" />
               </xs:restriction>
            </xs:simpleType>

            <xs:element name="type" type="res:Type"/>

            <xs:complexType name="Resource">
               <xs:sequence>
                  <xs:element name="title" type="xs:string" />
                  <xs:element name="referenceURL" type="xs:anyURI"
                              minOccurs="0"/>
                  <xs:element ref="res:type"
                              minOccurs="0" maxOccurs="unbounded"/>
               </xs:sequence>
               <xs:attribute name="created" type="xs:dateTime" />
            </xs:complexType>

            <xs:element name="resource" type="res:Resource" />

         </xs:schema>

             NVO Summer School 2005 - Aspen   7 September 2005        22
    Schema Documentation
    xmltech-documented.xml
                               <xs:complexType name="Resource">
                                  <xs:annotation>
                                     <xs:documentation>
                                       Any entity or component of a VO application that is
                                       describable and identifiable by a IVOA Identifier.
•   Most schema components           </xs:documentation>
    can have documentation        </xs:annotation>
    attached
                                 <xs:sequence>
                                    <xs:element name="title" type="xs:string" >
                                       <xs:annotation>
•   Documentation is                      <xs:documentation>
    important for defining                   the full name given to the resource
    metadata schemas                      </xs:documentation>
                                       </xs:annotation>
                                    </xs:element>
•   Carnivore registry              <xs:element name="referenceURL" type="xs:anyURI"
    extracts documentation                      minOccurs="0">
    directly from schema for           <xs:annotation>
    display to users                      <xs:documentation>
                                             URL pointing to a human-readable document
                                             describing this resource.
                                          </xs:documentation>
                                       </xs:annotation>
                                    </xs:element>
                                    …


                                NVO Summer School 2005 - Aspen   7 September 2005            23
Derived Types
     • Two ways to derive a new type from an existing one
          – Extension
               • Applicable only to complex types
               • Adds additional elements or attributes to the content model
<xs:complexType name="Service">
   <xs:complexContent>
      <xs:extension base="res:Resource">
         <xs:sequence>
            <xs:element name="accessURL" type="xs:anyURI" />
         </xs:sequence>
      </xs:extension>
   </xs:complexContent>
</xs:complexType>
<xs:element name="service" type="res:Service">

                        <service xmlns="http://nvoss.org/VOResource"
                                 created="1994-11-01T12:00:00" >
                           <title>ADIL Query Page</title>
                           <referenceURL>http://adil.ncsa.uiuc.edu/help.html</referenceURL>
                           <type>Archive</type>
                           <accessURL>http://adil.ncsa.uiuc.edu/QueryPage.html</accessURL>
                        </service>



                               NVO Summer School 2005 - Aspen    7 September 2005             24
Derived Types
  • Two ways to derive a new type from an existing one
     – Restriction
         • Simple types: restrict the legal values in some way
             Ex: integer: restrict range
                 string: restrict to match a pattern
         • Complex types:
             – Disallow optional elements, attributes
             – Restricting occurances
             – Setting default or fixed values where none were previously set




                         NVO Summer School 2005 - Aspen    7 September 2005     25
Extending Schemas I:
plugging-in derived entities

   • Suppose you want to define an element in
     terms of a base type but allow any type
     derived from it to be inserted in its place
      – a form of polymorphism


   • Two techniques
      – xsi:type
         • a label in the instance document)
      – Substitution groups
         • a label in the schema document



                      NVO Summer School 2005 - Aspen   7 September 2005   26
Extending Schemas I:
plugging-in derived entities
     • xsi:type technique
          From our example…
          – The resource element has the type Resource
          – The Service type is derived from the Resource type
          – Declaring a service element is not necessary
 In the schema document…                          In the instance document…
 <xs:element name="resourceList">                 <resourceList xmlns="http://nvoss.org/VOReso
    <xs:complexContent>                              <resource created="1994-11-01T12:00:00" >
       <xs:sequence>                                    <title>NCSA Astronomy Digital Image Li
          <xs:element name="resource"                   <referenceURL>http://adil.ncsa.uiuc.ed
                      type="res:Resource"               <type>Archive</type>
                      maxOccurs="unbounded" />       </resource>
       </xs:sequence>
    </xs:complexContent>                             <resource xsi:type="Service"
 </xs:element>                                                 created="1994-11-01T12:00:00" >
                                                        <title>ADIL Query Page</title>
                                                        <referenceURL>http://adil.ncsa.uiuc.ed
                                                        <type>Archive</type>
                                                        <accessURL>http://adil.ncsa.uiuc.edu/Q
                                                     </resource>
                                                  </resourceList>

       IVOA VOResource schema uses this technique
                                NVO Summer School 2005 - Aspen      7 September 2005       27
Extending Schemas I:
plugging-in derived entities

    • Substitution group technique
         From our example…
         – The Service type is derived from the Resource type
         – Add substitutionGroup attribute to service element definition
              • means we can substitute service element anywhere a resource is allowed
In the schema document…                            In the instance document…
<xs:element name="resource" type="res:Resource">   <resourceList xmlns="http://nvoss.org/VOReso
                                                      <resource created="1994-11-01T12:00:00" >
<xs:element name="service" type="res:Service"            <title>NCSA Astronomy Digital Image Li
            substitutionGroup="res:resource">            <referenceURL>http://adil.ncsa.uiuc.ed
<xs:element name="resourceList">                         <type>Archive</type>
   <xs:complexContent>                                </resource>
      <xs:sequence>                                   <service created="1994-11-01T12:00:00" >
         <xs:element ref="res:resource"                  <title>ADIL Query Page</title>
                     maxOccurs="unbounded" />            <referenceURL>http://adil.ncsa.uiuc.ed
      </xs:sequence>                                     <type>Archive</type>
   </xs:complexContent>                                  <accessURL>http://adil.ncsa.uiuc.edu/Q
</xs:element>                                         </service>
                                                   </resourceList>


        IVOA Space-Time Coordinates schema uses this technique

                                NVO Summer School 2005 - Aspen    7 September 2005          28
Extending Schemas II:
placing extensions into a separate namespace

  • separate schema file, separate namespace
     – Enables schema evolution in a backward compatible way.
     – Extension file uses xs:import to load schema being
       extended
     – Instance documents generally must define prefixes for
       both the original schema namespace and the extension
       namespace.
  • Example: VOResource metadata schemas
     – Core metadata schema: VOResource
     – Extension schemas: VODataCollection, VORegistry,
       ConeSearch, SimpleImageAccess



                     NVO Summer School 2005 - Aspen   7 September 2005   29
Extending Schemas II:
placing extensions into a separate namespace

  • separate schema file, separate namespace
     – Enables schema evolution in a backward compatible way.
     – Extension file uses xs:import to load schema being
       extended
     – Instance documents generally must define prefixes for
       both the original schema namespace and the extension
       namespace.
  • Example: VOResource metadata schemas
     – Core metadata schema: VOResource
     – Extension schemas: VODataCollection, VORegistry,
       ConeSearch, SimpleImageAccess



                     NVO Summer School 2005 - Aspen   7 September 2005   30
XPath

 • What it is:
    – A W3C standard syntax for pointing to elements,
      attributes, and/or their values in an XML file

 • Why you might care:
    – XPath is used in two other important XML technologies:
      XQuery and XSL
    – XPath is used in ADQL to query a registry via the
      standard Registry Interface

 • What you‟ll get from this session:
    – Ability to form simple XPath queries



                     NVO Summer School 2005 - Aspen   7 September 2005   31
Can you tell me how to get to
Sesame Street?
  • An XPath is a set of directions from one point in an XML
    document to another
         <NewYork>
            <Borough name="Brooklyn">
               <light/>
               <light/>
               <light>
                   <SesameStreet>
                      <weather>sunny</weather>
                   </SesameStreet>
               </light>
            </Borough>
            <Borough name="Queens"/>
         </NewYork>


  /NewYork/Burough[@name="Brooklyn“]/light[3]/SesameStreet

         Begin at the start of the document



                           NVO Summer School 2005 - Aspen   7 September 2005   32
Can you tell me how to get to
Sesame Street?
  • An XPath is a set of directions from one point in an XML
    document to another
         <NewYork>
            <Borough name="Brooklyn">
               <light/>
               <light/>
               <light>
                   <SesameStreet>
                      <weather>sunny</weather>
                   </SesameStreet>
               </light>
            </Borough>
            <Borough name="Queens"/>
         </NewYork>


  /NewYork/Burough[@name="Brooklyn“]/light[3]/SesameStreet

         Go to NewYork



                           NVO Summer School 2005 - Aspen   7 September 2005   33
Can you tell me how to get to
Sesame Street?
  • An XPath is a set of directions from one point in an XML
    document to another
         <NewYork>
            <Borough name="Brooklyn">
               <light/>
               <light/>
               <light>
                   <SesameStreet>
                      <weather>sunny</weather>
                   </SesameStreet>
               </light>
            </Borough>
            <Borough name="Queens"/>
         </NewYork>


  /NewYork/Burough[@name="Brooklyn"]/light[3]/SesameStreet

         Find the Borough named Brooklyn



                           NVO Summer School 2005 - Aspen   7 September 2005   34
Can you tell me how to get to
Sesame Street?
  • An XPath is a set of directions from one point in an XML
    document to another
         <NewYork>
            <Borough name="Brooklyn">
               <light/>
               <light/>
               <light>
                   <SesameStreet>
                      <weather>sunny</weather>
                   </SesameStreet>
               </light>
            </Borough>
            <Borough name="Queens"/>
         </NewYork>


  /NewYork/Burough[@name="Brooklyn"]/light[3]/SesameStreet

         Go to the 3rd light



                           NVO Summer School 2005 - Aspen   7 September 2005   35
Can you tell me how to get to
Sesame Street?
  • An XPath is a set of directions from one point in an XML
    document to another
         <NewYork>
            <Borough name="Brooklyn">
               <light/>
               <light/>
               <light>
                   <SesameStreet>
                      <weather>sunny</weather>
                   </SesameStreet>
               </light>
            </Borough>
            <Borough name="Queens"/>
         </NewYork>


  /NewYork/Burough[@name="Brooklyn"]/light[3]/SesameStreet

         And there‟s SesameStreet



                           NVO Summer School 2005 - Aspen   7 September 2005   36
XPath syntax
 • XPath fields (between the /s)
     – Each represents a descent in the XML hierarchy
         • “//” means drop any number of levels
     – Points to an XML node
         • element name or, if preceeded with an @, an attribute name
     – Other useful node-matching symbols
         * = wildcard (any name)   . = current node   .. = parent node

 • Context node = starting point
     – If it does not start with a /, XPath is relative to a context-specific
       starting point.
         /NewYork/Burough[@name="Brooklyn"]
         • @name is an XPath relative to /NewYork/Burough

 • Predicates: [ ]
     – Read “[…]” as “where …”
     – XPaths inside resolve to string value inside element/attribute pointed to
     – Operators: = != < > <= >= and or
     – Many Useful Functions: contains(string, string), position(),
       count(), last(), local-name()
     – [3] is short-hand for [position()=3]


                           NVO Summer School 2005 - Aspen    7 September 2005      37
XPath as a Query

 • An XPath returns matched XML nodes
      /NewYork/Burough[@name="Brooklyn“]/light[3]/SesameStreet

 On…                                           Returns…
 <NewYork>                                     <SesameStreet>
    <Borough name="Brooklyn">                     <weather>sunny</weather>
       <light/>                                </SesameStreet>
       <light/>
       <light>
           <SesameStreet>
              <weather>sunny</weather>
           </SesameStreet>
       </light>
    </Borough>
    <Borough name="Queens"/>
 </NewYork>




                             NVO Summer School 2005 - Aspen   7 September 2005   38
XPath as a Query

 • An XPath returns matched XML nodes
                             /NewYork/Burough/light

 On…                                           Returns…
 <NewYork>                                     <light/>
    <Borough name="Brooklyn">                  <light/>
       <light/>                                <light>
       <light/>                                   <SesameStreet>
       <light>                                       <weather>sunny</weather>
           <SesameStreet>                         </SesameStreet>
              <weather>sunny</weather>         </light>
           </SesameStreet>
       </light>
    </Borough>
    <Borough name="Queens"/>
 </NewYork>




                             NVO Summer School 2005 - Aspen   7 September 2005   39
XPath as a Query

 • An XPath returns matched XML nodes
              /NewYork/Burough/light/SesameStreet/weather

 On…                                           Returns…
 <NewYork>                                     <weather>sunny</weather>
    <Borough name="Brooklyn">
       <light/>
       <light/>
       <light>
           <SesameStreet>
              <weather>sunny</weather>
           </SesameStreet>
       </light>
    </Borough>
    <Borough name="Queens"/>
 </NewYork>




                             NVO Summer School 2005 - Aspen   7 September 2005   40
XPath as a Query

 • An XPath returns matched XML nodes
         string(/NewYork/Burough/light/SesameStreet/weather)

 On…                                           Returns…
 <NewYork>                                     sunny
    <Borough name="Brooklyn">
       <light/>
       <light/>
       <light>
           <SesameStreet>
              <weather>sunny</weather>
           </SesameStreet>
       </light>
    </Borough>
    <Borough name="Queens"/>
 </NewYork>




                             NVO Summer School 2005 - Aspen   7 September 2005   41
XPath as a Query

 • An XPath returns matched XML nodes
        /NewYork/Burough/light/SesameStreet[weather='sunny']

 On…                                           Returns…
 <NewYork>                                     <SesameStreet>
    <Borough name="Brooklyn">                     <weather>sunny</weather>
       <light/>                                </SesameStreet>
       <light/>
       <light>                                 weather was automatically converted
           <SesameStreet>
                                               to a string before comparison operator
              <weather>sunny</weather>
           </SesameStreet>                     was applied.
       </light>
    </Borough>
    <Borough name="Queens"/>
 </NewYork>




                             NVO Summer School 2005 - Aspen   7 September 2005      42
XPath as a Query
 • An XPath “returns” matched XML nodes
     – If path is ambiguous, all matching nodes are returned
     – If path does not resolve to an existing node, the empty set is returned
     – Predicates, […], provide constraints
 • In some contexts, XPath is automatically converted to string value
   inside the matched element or attribute.
 • Examples querying a set of VOResource documents
     /vr:resource[contains(vr:content/vr:description, 'cluster')]
     – Return all resource elements where the description contains the word
       „cluster‟
     /vr:resource[vr:facility]
     – Return all resources that have a facility element
     /vr:resource[@xsi:type='vr:ConeSearch']/vr:interface/vr:accessURL
     – Return the interface URLs of all ConeSearch services




                          NVO Summer School 2005 - Aspen   7 September 2005      43
XPath as a Query
 • An XPath “returns” matched XML nodes
     – If path is ambiguous, all matching nodes are returned
     – If path does not resolve to an existing node, the empty set is returned
     – Predicates, […], provide constraints
 • In some contexts, XPath is automatically converted to string value
   inside the matched element or attribute.
 • Examples querying a set of VOResource documents
     /vr:resource[contains(vr:content/vr:description, 'cluster')]
     – Return all resource elements where the description contains the word
       „cluster‟
     /vr:resource[vr:facility]
     – Return all resources that have a facility element
     /vr:resource[@xsi:type='vr:ConeSearch']/vr:interface/vr:accessURL
     – Return the interface URLs of all ConeSearch services




                          NVO Summer School 2005 - Aspen   7 September 2005      44
XQuery (a.k.a. XML Query)

 • What it is:
   – A W3C standard for querying XML documents
      • An analogue to SQL for tables
 • Why you might care:
   – It is one of the supported query languages in
     the standard VO Registry Interface.
   – It can handle certain complex registry queries
     that ADQL cannot
 • What you‟ll get from this session:
   – Ability to query XML documents by modifying
     existing an XQuery
                   NVO Summer School 2005 - Aspen   7 September 2005   45
XQuery: an analogy to SQL

 • SQL queries tables
   – Result of an SQL statement is a table
   – Columns of result table controlled by the
     SELECT clause
   – Rows controlled by the WHERE clause

 • XQuery queries XML documents
   – Result of an XQuery is an XML document
   – The form of the XML document is set by the
     return clause
   – The contents of the result is controlled by the
     for, let, and where clauses

                 NVO Summer School 2005 - Aspen   7 September 2005   46
XQuery syntax: think FLWOR

 • XQuery supports several types of
   expressions that can return XML results
   – XPath, Constructors, …
   – FLWOR = for let where orderby return
 • FLWOR clauses
   – for/let clause selects data from source XML
     documents




                 NVO Summer School 2005 - Aspen   7 September 2005   47
XQuery syntax: think FLWOR

                     declare namespace vr=
                         "http://www.ivoa.net/xml/VOResource/v0.10";
                     declare namespace vs=
                         "http://www.ivoa.net/xml/VODataService/v0.5";
                     for $vr in //vr:Resource[@xsi:type="cs:ConeSearch"]
                        where contains($vr//vr:description, "quasar")
                        return
                          <conesearch>
                            <title>{string($vr/vr:title)}</title>
                            <url>{string($vr/vr:interface/vs:accessURL)}</url>
                          </conesearch>



    • Searching for Cone Search services suitable
      for getting data about galaxy clusters
    • To be used with the Carnivore Registry




                 NVO Summer School 2005 - Aspen   7 September 2005          48
XQuery syntax: think FLWOR
  Declare namespace
  prefixes to use in query       declare namespace vr=
                                     "http://www.ivoa.net/xml/VOResource/v0.10";
                                 declare namespace vs=
                                     "http://www.ivoa.net/xml/VODataService/v0.5";
                                 for $vr in //vr:Resource[@xsi:type="cs:ConeSearch"]
                                    where contains($vr//vr:description, "quasar")
                                    return
                                      <conesearch>
                                        <title>{string($vr/vr:title)}</title>
                                        <url>{string($vr/vr:interface/vs:accessURL)}</url>
                                      </conesearch>



      • Searching for Cone Search services suitable
        for getting data about galaxy clusters
      • To be used with the Carnivore Registry




                             NVO Summer School 2005 - Aspen   7 September 2005          49
XQuery syntax: think FLWOR
    Declare namespace
    prefixes to use in query       declare namespace vr=
                                       "http://www.ivoa.net/xml/VOResource/v0.10";
 Loop over all ConeSearch          declare namespace vs=
                                       "http://www.ivoa.net/xml/VODataService/v0.5";
 resources                         for $vr in //vr:Resource[@xsi:type="cs:ConeSearch"]
                                      where contains($vr//vr:description, "quasar")
                                      return
                                        <conesearch>
                                          <title>{string($vr/vr:title)}</title>
                                          <url>{string($vr/vr:interface/vs:accessURL)}</url>
                                        </conesearch>

         • for clause sets up a loop around matching occurances
              – XPath both selects the Resource element node to put
                into the variable and constrains which Resources are
                included
         • let clause (not used here) can also set variables.
              – Used to join across documents, self-joins
              – If $vr is used in the variable definition, the new value
                would be different in each pass of the loop.

                               NVO Summer School 2005 - Aspen   7 September 2005          50
XQuery syntax: think FLWOR
    Declare namespace
    prefixes to use in query       declare namespace vr=
                                       "http://www.ivoa.net/xml/VOResource/v0.10";
 Loop over all ConeSearch          declare namespace vs=
                                       "http://www.ivoa.net/xml/VODataService/v0.5";
 resources                         for $vr in //vr:Resource[@xsi:type="cs:ConeSearch"]
                                      where contains($vr//vr:description, "quasar")
      Restrict output to              return
      ConeSearch services               <conesearch>
      about quasars                       <title>{string($vr/vr:title)}</title>
                                          <url>{string($vr/vr:interface/vs:accessURL)}</url>
                                        </conesearch>



         • where clause further restricts the output
              – Optional, often don‟t need it:
          for $vr in //vr:Resource[@xsi:type="cs:ConeSearch“ and
                                   contains($vr//vr:description, "quasar")]




                               NVO Summer School 2005 - Aspen   7 September 2005          51
XQuery syntax: think FLWOR
    Declare namespace
    prefixes to use in query       declare namespace vr=
                                       "http://www.ivoa.net/xml/VOResource/v0.10";
 Loop over all ConeSearch          declare namespace vs=
                                       "http://www.ivoa.net/xml/VODataService/v0.5";
 resources                         for $vr in //vr:Resource[@xsi:type="cs:ConeSearch"]
                                      where contains($vr//vr:description, "quasar")
      Restrict output to              return
      ConeSearch services               <conesearch>
      about quasars                       <title>{string($vr/vr:title)}</title>
                                          <url>{string($vr/vr:interface/vs:accessURL)}</url>
   Extract and display                  </conesearch>
   Desired information

         • return clause sets the output template
              – { } used to denote non-literal output
              – Applied to each value of $vr
         • XQuery supports several other expression types not
           shown here
              – Conditionals, function definition, etc.
              – Many more predefined funtions
                   XQuery: a full XML processing language

                               NVO Summer School 2005 - Aspen   7 September 2005          52
XSL – XML Stylesheet Language

 • What it is
    – A language for describing the transformation of XML
      data from one form to another
        • XML -> HTML
        • XML -> XML
        • XML -> Plain text

 • Why you might care
    – XSL can be used to create human readable renderings
      of XML data from the VO
    – XSL is used by the Java Skynode toolkit for converting
      ADQL to local SQL
 • What you‟ll get from this session:
    – Ability to modify XML transformations via simple changes to
      a stylesheet


                      NVO Summer School 2005 - Aspen   7 September 2005   53
XML Stylesheet Language
 • An XML document that describes a
   transformation
 • Contains a list of templates
   – Each describes the transformation for one type of node
     (e.g. an element with a particular name)
   – Node is identified by an XPath
      • Relative to current context node
   – Usually one template for /, the root of the document
   – A template can call other templates
 • XSL provides a number of programming
   structures
   – Conditionals, looping, user-defined functions, built-in
     functions, extensibilty
   – Variables are immutable!
 • XSLT = XSL Transformation
                    NVO Summer School 2005 - Aspen   7 September 2005   54
A tour through a stylesheet
xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text


                             <?xml version="1.0" encoding="UTF-8"?>
                             <xsl:stylesheet xmlns="http://www.ivoa.net/xml/VOResource/v0.10"
                                         xmlns:vr="http://www.ivoa.net/xml/VOResource/v0.10"
                                         xmlns:vs="http://www.ivoa.net/xml/VODataService/v0.5"
                                         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                         version="1.0">

                                <xsl:output method="text"/>

                                <xsl:template match="/">
                             Resource Description Record
                             <xsl:apply-templates select="vr:Resource" />
                                </xsl:template>




                                 NVO Summer School 2005 - Aspen    7 September 2005        55
A tour through a stylesheet
xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text


                             <?xml version="1.0" encoding="UTF-8"?>
   Define prefixes for       <xsl:stylesheet xmlns="http://www.ivoa.net/xml/VOResource/v0.10"
   all namespaces we‟ll                  xmlns:vr="http://www.ivoa.net/xml/VOResource/v0.10"
   be using                              xmlns:vs="http://www.ivoa.net/xml/VODataService/v0.5"
                                         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                         version="1.0">

                                <xsl:output method="text"/>

                                <xsl:template match="/">
                             Resource Description Record
                             <xsl:apply-templates select="vr:Resource" />
                                </xsl:template>




                                 NVO Summer School 2005 - Aspen    7 September 2005        56
A tour through a stylesheet
xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text


                             <?xml version="1.0" encoding="UTF-8"?>
   Define prefixes for       <xsl:stylesheet xmlns="http://www.ivoa.net/xml/VOResource/v0.10"
   all namespaces we‟ll                  xmlns:vr="http://www.ivoa.net/xml/VOResource/v0.10"
   be using                              xmlns:vs="http://www.ivoa.net/xml/VODataService/v0.5"
                                         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Our output format                        version="1.0">
will be plain text              <xsl:output method="text"/>

                                <xsl:template match="/">
                             Resource Description Record
                             <xsl:apply-templates select="vr:Resource" />
                                </xsl:template>




     • Three output types
          – xml, html, text



                                 NVO Summer School 2005 - Aspen    7 September 2005        57
A tour through a stylesheet
xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text


                             <?xml version="1.0" encoding="UTF-8"?>
   Define prefixes for       <xsl:stylesheet xmlns="http://www.ivoa.net/xml/VOResource/v0.10"
   all namespaces we‟ll                  xmlns:vr="http://www.ivoa.net/xml/VOResource/v0.10"
   be using                              xmlns:vs="http://www.ivoa.net/xml/VODataService/v0.5"
                                         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Our output format                        version="1.0">
will be plain text              <xsl:output method="text"/>

                                <xsl:template match="/">
                             Resource Description Record
  Our root document          <xsl:apply-templates select="vr:Resource" />
  template sets up the          </xsl:template>
  output document and
  calls next template


       • When raw text appears, XSLT engine will preserve spacing
         (like carriage returns) around text

       • vr:Resource is the root of our data document

                                 NVO Summer School 2005 - Aspen    7 September 2005        58
A tour through a stylesheet
xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text
                                    <xsl:template match="vr:Resource" >
        Resource template              <xsl:value-of select="substring-after(@xsi:type,':')"/>
                                       <xsl:text>
                                    </xsl:text>
                                       <xsl:value-of select="vr:title"/>
                                       <xsl:text> (</xsl:text>
                                       <xsl:value-of select="vr:shortName"/>
                                       <xsl:text>)
                                      IVOA Identifier:    </xsl:text>
                                       <xsl:value-of select="vr:identifier"/>
• When a template                      <xsl:apply-templates select="vr:content" />
  “runs”, it changes the               <xsl:apply-templates select="vr:curation" />
  context node to the               </xsl:template>

  node matched by the               <xsl:template match="vr:content">
  template                             <xsl:apply-templates select="vr:description" />
                                       <xsl:text>
• Subsequent XPaths                 </xsl:text>
  within template are                  <xsl:text>Target Communities: </xsl:text>
  relative to that                     <xsl:for-each select="vr:contentLevel">
  context node                             <xsl:value-of select="."/>
                                           <xsl:if test="position()!=last()">
                                               <xsl:text>, </xsl:text>
                                           </xsl:if>

                                       </xsl:for-each>
                                   </xsl:template>
                                 NVO Summer School 2005 - Aspen    7 September 2005         59
A tour through a stylesheet
xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text
                                    <xsl:template match="vr:Resource" >
        Resource template              <xsl:value-of select="substring-after(@xsi:type,':')"/>
                                       <xsl:text>
   text tags can be used to         </xsl:text>
   take explicit control of            <xsl:value-of select="vr:title"/>
   spacing                             <xsl:text> (</xsl:text>
                                       <xsl:value-of select="vr:shortName"/>
                                       <xsl:text>)
                                      IVOA Identifier:    </xsl:text>
                                       <xsl:value-of select="vr:identifier"/>
                                       <xsl:apply-templates select="vr:content" />
                                       <xsl:apply-templates select="vr:curation" />
                                    </xsl:template>

                                    <xsl:template match="vr:content">
                                       <xsl:apply-templates select="vr:description" />
                                       <xsl:text>
                                    </xsl:text>

                                       <xsl:text>Target Communities: </xsl:text>
                                       <xsl:for-each select="vr:contentLevel">
                                           <xsl:value-of select="."/>
                                           <xsl:if test="position()!=last()">
                                               <xsl:text>, </xsl:text>
                                           </xsl:if>

                                       </xsl:for-each>
                                   </xsl:template>
                                 NVO Summer School 2005 - Aspen    7 September 2005         60
  A tour through a stylesheet
  xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text
                                      <xsl:template match="vr:Resource" >
          Resource template              <xsl:value-of select="substring-after(@xsi:type,':')"/>
                                         <xsl:text>
     text tags can be used to         </xsl:text>
     take explicit control of            <xsl:value-of select="vr:title"/>
     spacing                             <xsl:text> (</xsl:text>
                                         <xsl:value-of select="vr:shortName"/>
   value-of will print the               <xsl:text>)
   string values of nodes               IVOA Identifier:    </xsl:text>
                                         <xsl:value-of select="vr:identifier"/>
                                         <xsl:apply-templates select="vr:content" />
                                         <xsl:apply-templates select="vr:curation" />
                                      </xsl:template>

                                      <xsl:template match="vr:content">
• our XPaths point to                    <xsl:apply-templates select="vr:description" />
  elements                               <xsl:text>
                                      </xsl:text>
    – Relative to vr:Resource!
• value-of will convert it to            <xsl:text>Target Communities: </xsl:text>
                                         <xsl:for-each select="vr:contentLevel">
  a string                                   <xsl:value-of select="."/>
                                             <xsl:if test="position()!=last()">
                                                 <xsl:text>, </xsl:text>
                                             </xsl:if>

                                         </xsl:for-each>
                                     </xsl:template>
                                   NVO Summer School 2005 - Aspen    7 September 2005         61
A tour through a stylesheet
xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text
                                    <xsl:template match="vr:Resource" >
        Resource template              <xsl:value-of select="substring-after(@xsi:type,':')"/>
                                       <xsl:text>
   text tags can be used to         </xsl:text>
   take explicit control of            <xsl:value-of select="vr:title"/>
   spacing                             <xsl:text> (</xsl:text>
                                       <xsl:value-of select="vr:shortName"/>
 value-of will print the               <xsl:text>)
 string values of nodes               IVOA Identifier:    </xsl:text>
                                       <xsl:value-of select="vr:identifier"/>
         Pass control to               <xsl:apply-templates select="vr:content" />
         other templates               <xsl:apply-templates select="vr:curation" />
                                    </xsl:template>

                                    <xsl:template match="vr:content">
                                       <xsl:apply-templates select="vr:description" />
                                       <xsl:text>
                                    </xsl:text>

                                       <xsl:text>Target Communities: </xsl:text>
                                       <xsl:for-each select="vr:contentLevel">
                                           <xsl:value-of select="."/>
                                           <xsl:if test="position()!=last()">
                                               <xsl:text>, </xsl:text>
                                           </xsl:if>

                                       </xsl:for-each>
                                   </xsl:template>
                                 NVO Summer School 2005 - Aspen    7 September 2005         62
    A tour through a stylesheet
    xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text
                                        <xsl:template match="vr:Resource" >
            Resource template              <xsl:value-of select="substring-after(@xsi:type,':')"/>
                                           <xsl:text>
       text tags can be used to         </xsl:text>
       take explicit control of            <xsl:value-of select="vr:title"/>
       spacing                             <xsl:text> (</xsl:text>
                                           <xsl:value-of select="vr:shortName"/>
     value-of will print the               <xsl:text>)
     string values of nodes               IVOA Identifier:    </xsl:text>
                                           <xsl:value-of select="vr:identifier"/>
             Pass control to               <xsl:apply-templates select="vr:content" />
             other templates               <xsl:apply-templates select="vr:curation" />
                                        </xsl:template>

                                        <xsl:template match="vr:content">
                                           <xsl:apply-templates select="vr:description" />
     Loop over all occurances              <xsl:text>
     of contentLevel                    </xsl:text>

                                           <xsl:text>Target Communities: </xsl:text>
•    Normally, apply-templates             <xsl:for-each select="vr:contentLevel">
     will automatically loop over              <xsl:value-of select="."/>
     multiple occurances                       <xsl:if test="position()!=last()">
                                                   <xsl:text>, </xsl:text>
•    Here, we need to insert                   </xsl:if>
     commas
•    for-each also changes the             </xsl:for-each>
     context node                      </xsl:template>
                                     NVO Summer School 2005 - Aspen    7 September 2005         63
    A tour through a stylesheet
    xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text
                                        <xsl:template match="vr:Resource" >
            Resource template              <xsl:value-of select="substring-after(@xsi:type,':')"/>
                                           <xsl:text>
       text tags can be used to         </xsl:text>
       take explicit control of            <xsl:value-of select="vr:title"/>
       spacing                             <xsl:text> (</xsl:text>
                                           <xsl:value-of select="vr:shortName"/>
     value-of will print the               <xsl:text>)
     string values of nodes               IVOA Identifier:    </xsl:text>
                                           <xsl:value-of select="vr:identifier"/>
             Pass control to               <xsl:apply-templates select="vr:content" />
             other templates               <xsl:apply-templates select="vr:curation" />
                                        </xsl:template>

                                        <xsl:template match="vr:content">
                                           <xsl:apply-templates select="vr:description" />
     Loop over all occurances              <xsl:text>
     of contentLevel                    </xsl:text>

                                           <xsl:text>Target Communities: </xsl:text>
                        If block           <xsl:for-each select="vr:contentLevel">
                                               <xsl:value-of select="."/>
                                               <xsl:if test="position()!=last()">
                                                   <xsl:text>, </xsl:text>
•    Use choose/when for if-then-else          </xsl:if>
     blocks
                                           </xsl:for-each>
                                       </xsl:template>
                                     NVO Summer School 2005 - Aspen    7 September 2005         64
XSL for metadata

 • Transformation is a powerful paradigm for
   metadata processing
   – Consider all uses of metadata as a
     transformation to another form…
      • User display
      • An SQL statement
      • A workflow script
      • Compilable code
   – XSL stylesheet somewhere between
     configuration file and script
      • Rapid prototyping and adaptation
      • xsl:import: ability to extend & override other
        stylesheets


                  NVO Summer School 2005 - Aspen   7 September 2005   65

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:4
posted:1/2/2012
language:
pages:65