Data Integration through XML/XSLT Presenter: Xin Gu
q7.jar op.xsl goalmodel.q7 goalmodel.xml q7.xsl help, hurt GUI +, -, ++, -- goalmodel.op.xml merge.xsl goalmodel.input.xml profile.xml Goal model configurator goalmodel.output.xml config.xml leaf goals (true/false) param. (integer,string) config.xsl config.properties
XML (extensible Markup Language) Markup in XML A sequence of characters inserted into a text file, to indicate how the file should be displayed, or to describe the logical structure. Markup is everything in a document that is not content. Initially used in typesetting a document Markup indicators are called tags. e.g. <font color= blue > A pair of tags and the things enclosed in tags is called element. e.g. <font color= blue > formatted as blue </font>
What is XML (extensible Markup Language) (cont.) Extensible In general: Something that is designed that users or later designers can extend its capability. In XML: Allow you to define your own tags to describe data You can represent any information (define new tags) You can represent in the way you want (define new structure) XML is a meta-language A language to define other languages Use DTD to define the syntax of a language
XML Element An element consists of: an opening tag the content a closing tag Example: <lecturer>david Billington</lecturer> Tag names can be chosen almost freely: The first character must be a letter, an underscore, or a colon No name may begin with the string xml in any combination of cases E.g. Xml, xml
Contents of XML Elements Content may be text, or other elements, or nothing <lecturer> <name>david Billington</name> <phone> +61 7 3875 507 </phone> </lecturer> If there is no content, then the element is called empty; it is abbreviated as follows: <lecturer/> <lecturer></lecturer>
Attributes An attribute is a name-value pair inside the opening tag of an element <lecturer name="david Billington" phone="+61 7 3875 507"/> Example <order orderno="23456" customer="john Smith" date="october 15, 2002"> <item itemno="a528" quantity="1"/> <item itemno="c817" quantity="3"/> </order>
Element and Attribute <order> <orderno>23456</orderno> <customer>john Smith</customer> <date>october 15, 2002</date> <item> <itemno>a528</itemno> <quantity>1</quantity> </item> <item> <itemno>c817</itemno> <quantity>3</quantity> </item> </order> <order orderno="23456" customer="john Smith" date="october 15, 2002"> <item itemno="a528 quantity="1"/> <item itemno="c817 quantity="3"/> </order> Attributes can be replaced by elements When to use elements and when attributes is a matter of taste But attributes cannot be nested.
Further Components of XML Comments A piece of text that is to be ignored by parser <!-- This is a comment --> Processing Instructions (PIs) Define procedural attachments <?stylesheet type="text/css" href="mystyle.css"?>
XSLT(XML Stylesheet Language Transformation) XSLT Version 1.0 is a W3C Recommendation, 1999 http://www.w3.org/style/xsl/ XSLT is used to transform XML to other formats XSLT 1 XML XML XSLT 2 HTML XSLT 3 TEXT
XSLT basics XSLT is an XML document itself It is a tree transformation language XSLT XML XSLT processor It is a rule-based declarative language XSLT program consists of a sequence of rules. It is a functional programming language.
XSL Templates An XSL style sheet consists of one or more set of rules that are called templates. Each template contains rules to apply when a specified node is matched. The <xsl:template> element is used to build templates. The match attribute is used to associate a template with an XML element.
XSLT Example: transform to another XML <?xml version="1.0"?> <stocks> <stock exchange="nasdaq"> <name>amazon corp </name> <symbol>amzn</symbol> <price>16</price> </stock> <stock exchange="nyse"> <name>ibm inc</name> <price>102</price> </stock> </stocks> stock.xml? <?xml version="1.0 > <companies> <company> <value>24 CAD </value> <name>amazon corp</name> </company> <company> <value>153 CAD </value> <name>ibm inc</name> </company> </companies> output Rename the element names Remove the attribute and the symbol element Change the order between name and price. Change the US dollar to CAD.
XSLT rule: <xsl:template> <xsl:template match="stock"> <company> <value> <xsl:value-of select="price*1.5"/> CAD </value> <name> <xsl:value-of select="name"/> </name> <company> </xsl:template> xslt template for <stock> <?xml version="1.0"?> <stocks> <stock exchange="nasdaq"> <name>amazon corp </name> <symbol>amzn</symbol> <price>16</price> </stock> <stock exchange="nyse"> <name>ibm inc</name> <price>102</price> </stock> </stocks> stock.xml <company> <value> get the value of <price>* 1.5, i.e. 24 CAD </value> <name> get the value of <name>, i.e amazon </name> </company> Part of the output