Πανεπιστήμιο Πειραιώς Τμήμα Ψηφιακών Συστημάτων Σημασιολογικός Ιστός (Semantic Web) - XML 29/11/2016 Δρ. Ανδριάνα Πρέντζα Αναπληρώτρια Καθηγήτρια aprentza@unipi.gr
Πανεπιστήμιο Πειραιά Τμήμα Ψηφιακών Συστημάτων XSL extensible Stylesheet Language
Extensible Stylesheet Language (XSL)
Τα στοιχεία ενός XSL αρχείου 1/2 <xsl:template match= tag-name > Ορίζει τον HTML κώδικα για ένα συγκεκριμένο XML tag <xsl:value-of select= tag-name > </xsl:value-of> Επιστρέφει την τιμή ενός attribute ενός tag ή το κείμενο που σχετίζεται με έναν κόμβο του XML κειμένου <xsl:for-each select= tag-name > <xsl:for-each> Επαναλαμβάνει ότι ακολουθεί για κάθε tag που ταιριάζει με το συγκεκριμένο tag name. <xsl:sort select= tag-name /> Ορίζει με βάση ποιο tag να γίνει η ταξινόμηση
Τα στοιχεία ενός XSL αρχείου 2/2 <xsl:if test="price > 10">...</xsl:if> Εάν η συνθήκη παίρνει την τιμή true τότε εμφανίζεται το αποτέλεσμα στον browser <xsl:choose> <xsl:when test="price > 10">...</xsl:when> <xsl:otherwise>...</xsl:otherwise> </xsl:choose> <xsl:apply-templates match= name /> Εφαρμόζει όλα τα δυνατά templates στα tags που ταιριάζουν στην περιγραφή <xsl:element name = Name >...</xsl:element> Ορίζει ένα element δυναμικά <xsl:attribute name = Name >Value</xsl:attribute> Ορίζει ένα attribute για ένα element
Παράδειγμα
XML έγγραφο <?xml version="1.0"?> <catalog> <cd> <title>empire Burlesque</title> <artist>bob Dylan</artist> <country>usa</country> <company>columbia</company> <price>10.90</price> <year>1985</year> </cd>...
<xsl:value-of> <xsl:value-of select= tag-name > </xsl:value-of> Χρησιμοποιείται για την επιλογή στοιχείων XML στο ρεύμα εξόδου (output stream) του μετασχηματισμού της XSL Επιστρέφει την τιμή ενός attribute ενός element ή ενός κόμβου του XML αρχείου Το πεδίο select είναι απαραίτητο και περιέχει μία XPath expression Χρησιμοποιεί το forward slash (/) για να επιλέγει υπο-καταλόγους <xsl:value-of select = catalog/cd/title"/> XSL αρχείο XML αρχείο
<xsl:value-of>
<xsl:value-of> Γιατί δεν επιστρέφονται οι τιμές Title και Artist για όλα τα elements cd? Επειδή η <xsl:value-of> επιλέγει μόνο το πρώτο στοιχείο (σε περίπτωση επιλογής από πολλά) ΟΠΟΤΕ?
<xsl:for-each> <xsl:for-each select= tag-name > </xsl:for-each> Χρησιμοποιείται για την επιλογή όλων των στοιχείων XML στο ρεύμα εξόδου (output stream) του μετασχηματισμού της XSL Επιτρέπει τον ορισμό looping στο XSLT Ότι περιέχεται μεταξύ του start και end tag επαναλαμβάνεται για όσα XML elements ταιριάζουν με το tag name που έχει επιλεχθεί Το πεδίο select είναι απαραίτητο και περιέχει μία XPath expression <xsl:for-each select="catalog/cd"> <tr><td><xsl:value-of select="title" /></td> <td><xsl:value-of select="artist" /></td></tr> </xsl:for-each> XSL αρχείο XML αρχείο
@ and / Το @ αναφέρεται στην τιμή του attribute Το / αναφέρεται στο root node, Όταν χρησιμοποιείται μεταξύ ονομάτων τότε ορίζει ότι το δεύτερο στοιχείο είναι παιδί του πρώτου Example: <xsl:template match= Ingredient/Qty > <xsl:value-of select= @unit />
* and // Το wildcard * αντικαθιστά ένα οποιοδήποτε στοιχείο σε μία ιεραρχία <xsl:template match= Recipe/*/Ingredient > Αναφέρεται σε όλα τα elements Ingredient που είναι εγγόνια του node Recipe Το σύμβολο // στην αρχή ενός pattern αναφέρεται σε ένα node απόγονο σε οποιοδήποτε επίπεδο <xsl:template match= //Recipe >
<xsl:for-each> + κριτήριο Στο πεδίο select μπορούμε να προσθέσουμε ένα κριτήριο για να φιλτράρουμε τα δεδομένα από ένα XML αρχείο <xsl:for-each select="catalog/cd[artist='bob Dylan']"> Τελεστές φιλτραρίσματος = (ίσο)!= (διάφορο) < (< μικρότερο) > (> μεγαλύτερο) XSL αρχείο XML αρχείο
<xsl:for-each> + κριτήριο
<xsl:for-each> + κριτήριο
<xsl:sort> Ταξινόμηση αποτελέσματος <xsl:sort select= tag-name /> Το element sort πρέπει να μπει μέσα στο for-each element στο XSL αρχείο <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <tr><td><xsl:value-of select="title" /></td> <td><xsl:value-of select="artist" /></td></tr> </xsl:for-each> <xsl:sort select="artist" order= descending /> Το πεδίο select δηλώνει με βάση ποιο XML element θα γίνει η ταξινόμηση XSL αρχείο XML αρχείο
<xsl:if> Το element <xsl:if match=.[name= value ] > μας επιτρέπει να εφαρμόσουμε ένα σύνολο από rules ανάμεσα στο tag αρχής και τέλους αν η τιμή των elements ή attributes ταιριάζει με την τιμή στη δεξιά πλευρά του συμβόλου =. Με άλλα λόγια, το <xsl:if> επιτρέπει να ανακτήσουμε υπό συνθήκη την τιμή των elements ή attributes. Η συνθήκη τοποθετείται ως τιμή στο attribute match. Το συντακτικό για το <xsl:if> που προτείνει το W3C είναι: <xsl:if test ="major/@decided = 'n'">
<xsl:if> Με το συντακτικό για το <xsl:if>, το <xsl:stylesheet> tag θα πρέπει να είναι το: <xsl:stylesheet version="1.0 xmlns:xsl="http://www.w3.org/1999/xsl/transform"> Και όχι το: <xsl:stylesheet xmlns:xsl="http://www.w3.org/tr/wd-xsl"> Μπορούμε να χρησιμοποιήσουμε οποιοδήποτε από τα δύο, αλλά η δεύτερη περίπτωση δουλεύει μόνο για τον Internet Explorer.
<xsl:if> <xsl:if test="price > 10">...</xsl:if> Το περιεχόμενο του if element εμφανίζεται εάν η συνθήκη είναι αληθής (true) Το if element μπορεί να τοποθετηθεί οπουδήποτε μέσα σε ένα XSL αρχείο <xsl:if test="price > 10"> some output... </xsl:if> Το πεδίο test είναι απαραίτητο και περιέχει τη συνθήκη που θα ελεγχθεί XSL αρχείο XML αρχείο
<xsl:choose> Το element <xsl:choose> χρησιμοποιείται σε συνδυασμό με τα <xsl:when>, <xsl:otherwise> για να δηλώσει πολλές συνθήκες. Σύνταξη: <xsl:choose> <xsl:when test="expression">... some output... </xsl:when> <xsl:otherwise>... some output... </xsl:otherwise> </xsl:choose>
<xsl:choose> Για πολλαπλούς ελέγχους συνθήκης <xsl:choose> <xsl:when test="price > 10">...</xsl:when> <xsl:otherwise>...</xsl:otherwise> </xsl:choose> Το choose element μπορεί να τοποθετηθεί οπουδήποτε μέσα σε ένα XSL αρχείο XSL αρχείο XML αρχείο
<xsl:choose> Για πολλαπλούς ελέγχους συνθήκης <xsl:choose> <xsl:when test="price > 10">...</xsl:when> <xsl:otherwise>...</xsl:otherwise> </xsl:choose> Το element when μπορεί να εμφανίζεται πάνω από μία φορές μέσα σε ένα choose XSL αρχείο XML αρχείο
<xsl:apply-templates> Το element <xsl:apply-templates> δημιουργεί ένα template για το τρέχον element ή για τα child nodes του τρέχοντος element. Προσθέτοντας μία select attribute στο <xsl:applytemplates> element προωθούμε μόνο το child element, στο οποίο ταιριάζει η τιμή της attribute. Μπορούμε να χρησιμοποιήσουμε την select attribute για να προσδιορίσουμε τη σειρά, με την οποία τα child nodes προωθούνται. Μπορεί να χρησιμοποιηθεί ως εναλλακτική του <xsl:for-each>.
<xsl:apply-templates> <xsl:apply-templates> Εφαρμόζει ένα template στο τρέχον element ή στο παιδί του τρέχοντος element Είναι δυνατό να επιλεγεί σε ποιο element θα εφαρμοστούν τα templates <xsl:apply-templates select="title"/> Το πεδίο select μπορεί να χρησιμοποιηθεί για να καθοριστεί η σειρά επεξεργασίας των παιδιών ενός element <xsl:template match="cd"><p> XSL αρχείο <xsl:apply-templates select="title"/> <xsl:apply-templates select="artist"/></p> XML αρχείο
Default XSLT Templates Templa te / Description <xsl:template match = "/ *"> <xsl:apply-templates/> This template matches the document root node (/) and any element nodes (*) of an XML document and applies templates to their child nodes. <xsl:template match = "text() @*"> <xsl:value-of select = "."/> This template matches text nodes (text()) and attribute nodes (@) and outputs their values. <xsl:template match = "processing-instruction() comment()"/> This template matches processing-instruction nodes (processing-instruction()) and comment nodes (comment()), but does not perform any actions with them. 2002 Prentice Hall, Inc. All rights reserved.
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 12.8 : usage.xml --> 4 <!-- Usage of elements and attributes --> 5 6 <?xml:stylesheet type = "text/xsl" href = "usage.xsl"?> 7 8 <book isbn = "999-99999-9-X"> 9 <title>deitel's XML Primer</title> 10 11 <author> 12 <firstname>paul</firstname> 13 <lastname>deitel</lastname> 14 </author> 15 16 <chapters> 17 <preface num = "1" pages = "2">Welcome</preface> 18 <chapter num = "1" pages = "4">Easy XML</chapter> 19 <chapter num = "2" pages = "2">XML Elements?</chapter> 220 20 <chapter num = 3" pages = 4">XML Made easy</chapter> 21 <chapter num = 4" pages = 5">XPath</chapter> 22 <chapter num = 5" pages = 1">XPointers</chapter> 23 <appendix num = "1" pages = "9">Entities</appendix> 24 </chapters> 25 26 <media type = "CD"/> 27 </book> 2002 Prentice Hall, Inc. All rights reserved.
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 12.8 : usage.xml --> 4 <!-- Usage of elements and attributes --> 5 6 <?xml:stylesheet type = "text/xsl" href = "usage.xsl"?> 7 8 <book isbn = "999-99999-9-X"> 9 <title>deitel's XML Primer</title> 10 11 <author> 12 <firstname>paul</firstname> 13 <lastname>deitel</lastname> 14 </author> 15 16 <chapters> 17 <preface num = "1" pages = "2">Welcome</preface> 18 <chapter num = "1" pages = "4">Easy XML</chapter> 19 <chapter num = "2" pages = "2">XML Elements?</chapter> 220 20 <chapter num = 3" pages = 4">XML Made easy</chapter> 21 <chapter num = 4" pages = 5">XPath</chapter> 22 <chapter num = 5" pages = 1">XPointers</chapter> 23 <appendix num = "1" pages = "9">Entities</appendix> 24 </chapters> 25 26 <media type = "CD"/> 27 </book> 2002 Prentice Hall, Inc. All rights reserved.
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 12.9 : usage.xsl --> 4 <!-- Transformation of Book information into HTML --> 5 6 <xsl:stylesheet version = "1.0" 7 xmlns:xsl = "http://www.w3.org/1999/xsl/transform"> 8 9 <xsl:template match = "/"> 10 <html> 11 <xsl:apply-templates/> 12 </html> 13 14 15 <xsl:template match = "book"> 16 <head> 17 <title>isbn <xsl:value-of select = "@isbn"/> - 18 <xsl:value-of select = "title"/></title> 19 </head> 20 21 <body bgcolor = "white"> 22 <h1><xsl:value-of select = "title"/></h1> 23 24 <h2>by <xsl:value-of select = "author/lastname"/>, 25 <xsl:value-of select = "author/firstname"/></h2> 26 27 <table border = "1"> 28 <xsl:for-each select = "chapters/preface"> Element for-each applies element contents to each preface element node Use element sort to sort nodes (selected by foreach) in ascending order 29 <xsl:sort select = "@num" order = "ascending"/> 2002 Prentice Hall, Inc. All rights reserved.
30 <tr> 31 <td align = "right"> 32 Preface <xsl:value-of select = "@num"/> 33 </td> 34 35 <td> 36 <xsl:value-of select = "."/> ( 37 <xsl:value-of select = "@pages"/> pages ) 38 </td> 39 </tr> 40 </xsl:for-each> 41 42 <xsl:for-each select = "chapters/chapter"> 43 <xsl:sort select = "@num" order = "ascending"/> 44 <tr> 45 <td align = "right"> 46 Chapter <xsl:value-of select = "@num"/> 47 </td> 48 49 <td> 50 <xsl:value-of select = "."/> ( 51 <xsl:value-of select = "@pages"/> pages ) 52 </td> 53 </tr> 54 </xsl:for-each> 55 56 <xsl:for-each select = "chapters/appendix"> 57 <xsl:sort select = "@num" order = "ascending"/> 58 <tr> 59 <td align = "right"> 60 Appendix <xsl:value-of select = "@num"/> 61 </td> Iterate and sort chapter elements Iterate and sort appendix elements 2002 Prentice Hall, Inc. All rights reserved.
62 63 <td> 64 <xsl:value-of select = "."/> ( 65 <xsl:value-of select = "@pages"/> pages ) 66 </td> 67 </tr> 68 </xsl:for-each> 69 </table> 70 </body> 71 72 73 </xsl:stylesheet> 2002 Prentice Hall, Inc. All rights reserved.
1 <html> 2 <head> 3 <title>isbn 999-99999-9-X - Deitel's XML Primer</title> 4 </head> 5 6 <body bgcolor = "white"> 7 <h1>deitel's XML Primer</h1> 8 <h2>by Deitel, Paul</h2> 9 10 <table border = "1"> 11 <tr> 12 <td align = "right">preface 1</td> 13 <td>welcome ( 2 pages )</td> 14 </tr> 15 16 <tr> 17 <td align = "right">chapter 1</td> 18 <td>easy XML ( 4 pages )</td> 19 </tr> 20 21 <tr> 22 <td align = "right">chapter 2</td> 23 <td>xml Elements? ( 2 pages )</td> 24 </tr> 25 26 <tr> 27 <td align = "right">appendix 1</td> 28 <td>entities ( 9 pages )</td> 29 </tr> 30 </table> 31 </body> 32 33 </html> 2002 Prentice Hall, Inc. All rights reserved.
Output 2002 Prentice Hall, Inc. All rights reserved.
Δημιουργία στοιχείων και ιδιοτήτων
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 12.4 : games.xml --> 4 <!-- Sports Database --> 5 6 <sports> 7 8 <game title = "cricket"> 9 <id>243</id> 10 11 <para> 12 More popular among commonwealth nations. 13 </para> 14 </game> 15 16 <game title = "baseball"> 17 <id>431</id> 18 19 <para> 20 More popular in America. 21 </para> 22 </game> 23 24 <game title = "soccer"> 25 <id>123</id> 26 27 <para> 28 Most popular sport in the world. 29 </para> 30 </game> 31 32 </sports> XML document containing a list of sports. 1 <?xml version = "1.0" encoding = "UTF-8" 2 <sports> 3 4 <cricket id = "243"> 5 <comment> 6 More popular among commonwealth 7 </comment> 8 </cricket> 9 10 <baseball id = "431"> 11 <comment> 12 More popular in America. 13 </comment> 14 </baseball> 15 16 <soccer id = "123"> 17 <comment> 18 Most popular sport in the world 19 </comment> 20 </soccer> 21 22 </sports> 2002 Prentice Hall, Inc. All rights reserved.
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 12.5 : elements.xsl --> 4 <!-- Using xsl:element and xsl:attribute --> 5 6 <xsl:stylesheet version = "1.0" 7 xmlns:xsl = "http://www.w3.org/1999/xsl/transform"> 8 9 <xsl:template match = "/"> 10 <xsl:apply-templates/> 11 12 13 <xsl:template match = "sports"> 14 <sports> 15 <xsl:apply-templates/> 16 </sports> 17 18 19 <xsl:template match = "game"> 20 <xsl:element name = "{@title}"> 21 22 <xsl:attribute name = "id"> 23 <xsl:value-of select = "id"/> 24 </xsl:attribute> 25 26 <comment> 27 <xsl:value-of select = "para"/> 28 </comment> 29 30 </xsl:element> 31 32 33 </xsl:stylesheet> Using XSLT to create elements and attributes. Use attribute match to select XML document root Element apply-templates applies XSLT document templates to specific nodes match element sports and apply templates to sport node s child nodes Create element title Create attribute id for element title Create comment with element para comments 2002 Prentice Hall, Inc. All rights reserved.
1 <?xml version = "1.0" encoding = "UTF-8"?> 2 <sports> 3 4 <cricket id = "243"> 5 <comment> 6 More popular among commonwealth nations. 7 </comment> 8 </cricket> 9 10 <baseball id = "431"> 11 <comment> 12 More popular in America. 13 </comment> 14 </baseball> 15 16 <soccer id = "123"> 17 <comment> 18 Most popular sport in the world. 19 </comment> 20 </soccer> 21 22 </sports> Output of transformation 2002 Prentice Hall, Inc. All rights reserved.
1) Select the Xpath expression that fits in ----(1)----- of XSLT Stylesheet when XSLT Stylesheet is applied to the given XML Document to output Transformation Results. XML Document <?xml version="1.0" encoding="utf-8"?> <UserList> <UserID Password="xxxxxx" authority="administrator">user01</userid> <UserID Password="zzzzzz" authority="general">user02</userid> <UserID Password="xyzxyz" authority="system">user03</userid> <UserID Password="yyyyyy" authority="general">user04</userid> </UserList> Transformation Results <?xml version="1.0" encoding="utf-8"?> <GeneralUserList> <UserID>User02</UserID> <authority>general</authority> <UserID>User04</UserID> <authority>general</authority> </GeneralUserList>
1) Select the Xpath expression that fits in ----(1)----- of XSLT Stylesheet when XSLT Stylesheet is applied to the given XML Document to output Transformation Results. XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <GeneralUserList> <xsl:apply-templates select= ----(1)-----" /> </GeneralUserList> <xsl:template match="userid"> <UserID><xsl:value-of select="text()" /></UserID> <xsl:element name="authority"> <xsl:value-of select="@authority" /> </xsl:element> </xsl:stylesheet> a) UserList/UserID[@authority= general ] b) UserList/UserID/@authority= general c) UserList/UserID/[@authority= general ] d) There is no correct description
2) Select which of the following is the correct transformation result when XSLT Stylesheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <UserList> <UserID Password="xxxxxx" authority="administrator">user01</userid> <UserID Password="zzzzzz" authority="general">user02</userid> <UserID Password="xyzxyz" authority="system">user03</userid> <UserID Password="yyyyyy" authority="general">user04</userid> </UserList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <SystemUserList> <xsl:apply-templates select="userlist/userid" /> </SystemUserList> <xsl:template match="userid"> <xsl:if test="@authority='system'"> <UserID><xsl:value-of select="text()" /></UserID> <xsl:element name="authority"><xsl:value-of select="@authority" /></xsl:element> </xsl:if> </xsl:stylesheet> a. <?xml version="1.0" encoding="utf-8"?> <UserID>User03</UserID> <authority>system</authority>
2) Select which of the following is the correct transformation result when XSLT Styelsheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <UserList> <UserID Password="xxxxxx" authority="administrator">user01</userid> <UserID Password="zzzzzz" authority="general">user02</userid> <UserID Password="xyzxyz" authority="system">user03</userid> <UserID Password="yyyyyy" authority="general">user04</userid> </UserList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <SystemUserList> <xsl:apply-templates select="userlist/userid" /> </SystemUserList> <xsl:template match="userid"> <xsl:if test="@authority='system'"> <UserID><xsl:value-of select="text()" /></UserID> <xsl:element name="authority"><xsl:value-of select="@authority" /></xsl:element> </xsl:if> </xsl:stylesheet> <SystemUserList> b. <?xml version="1.0" encoding="utf-8"?> <UserID>User03</UserID> </SystemUserList>
2) Select which of the following is the correct transformation result when XSLT Styelsheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <UserList> <UserID Password="xxxxxx" authority="administrator">user01</userid> <UserID Password="zzzzzz" authority="general">user02</userid> <UserID Password="xyzxyz" authority="system">user03</userid> <UserID Password="yyyyyy" authority="general">user04</userid> </UserList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <SystemUserList> <xsl:apply-templates select="userlist/userid" /> </SystemUserList> <xsl:template match="userid"> <xsl:if test="@authority='system'"> <UserID><xsl:value-of select="text()" /></UserID> <xsl:element name="authority"><xsl:value-of select="@authority" /></xsl:element> </xsl:if> </xsl:stylesheet> <SystemUserList> c. <?xml version="1.0" encoding="utf-8"?> <authority>system</authority> <UserID>User03</UserID> </SystemUserList>
2) Select which of the following is the correct transformation result when XSLT Styelsheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <UserList> <UserID Password="xxxxxx" authority="administrator">user01</userid> <UserID Password="zzzzzz" authority="general">user02</userid> <UserID Password="xyzxyz" authority="system">user03</userid> <UserID Password="yyyyyy" authority="general">user04</userid> </UserList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <SystemUserList> <xsl:apply-templates select="userlist/userid" /> </SystemUserList> <xsl:template match="userid"> <xsl:if test="@authority='system'"> <UserID><xsl:value-of select="text()" /></UserID> <xsl:element name="authority"><xsl:value-of select="@authority" /></xsl:element> </xsl:if> </xsl:stylesheet> <SystemUserList> d. <?xml version="1.0" encoding="utf-8"?> <UserID>User03</UserID> <authority>system</authority> </SystemUserList>
3) Select the correct description that fits in (1) of XSLT Stylesheet to obtain Transformation Results when XSLT Stylesheet is applied to the XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> < ProductList> <ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> <ProductName ProductID="X01-0002">XML SchemaProblemSet2</ProductName> <ProductName ProductID="X01-0003">XSLTProblemSet1</ProductName> <ProductName ProductID="X01-0004">XSLTProblemSet2</ProductName> < /ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> < xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <xsl:apply-templates select="productlist/productname" /> <xsl:template match="productname"> ( 1 ) < /xsl:stylesheet> Transformation Results <?xml version="1.0" encoding="utf-8"?> < ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> a. < xsl:if test="@productid='x01-0001'"> <xsl:copy /> < /xsl:if>
3) Select the correct description that fits in (1) of XSLT Stylesheet to obtain Transformation Results when XSLT Stylesheet is applied to the XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> < ProductList> <ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> <ProductName ProductID="X01-0002">XML SchemaProblemSet2</ProductName> <ProductName ProductID="X01-0003">XSLTProblemSet1</ProductName> <ProductName ProductID="X01-0004">XSLTProblemSet2</ProductName> < /ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> < xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <xsl:apply-templates select="productlist/productname" /> <xsl:template match="productname"> ( 1 ) < /xsl:stylesheet> Transformation Results <?xml version="1.0" encoding="utf-8"?> < ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> b. < xsl:if test="@productid='x01-0001'"> <xsl:copy-of select="." /> < /xsl:if>
3) Select the correct description that fits in (1) of XSLT Stylesheet to obtain Transformation Results when XSLT Stylesheet is applied to the XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> < ProductList> <ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> <ProductName ProductID="X01-0002">XML SchemaProblemSet2</ProductName> <ProductName ProductID="X01-0003">XSLTProblemSet1</ProductName> <ProductName ProductID="X01-0004">XSLTProblemSet2</ProductName> < /ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> < xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <xsl:apply-templates select="productlist/productname" /> <xsl:template match="productname"> ( 1 ) < /xsl:stylesheet> Transformation Results <?xml version="1.0" encoding="utf-8"?> < ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> c. < xsl:if test="@productid='x01-0001'"> <xsl:copy select="." /> < /xsl:if>
3) Select the correct description that fits in (1) of XSLT Stylesheet to obtain Transformation Results when XSLT Stylesheet is applied to the XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> < ProductList> <ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> <ProductName ProductID="X01-0002">XML SchemaProblemSet2</ProductName> <ProductName ProductID="X01-0003">XSLTProblemSet1</ProductName> <ProductName ProductID="X01-0004">XSLTProblemSet2</ProductName> < /ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> < xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <xsl:apply-templates select="productlist/productname" /> <xsl:template match="productname"> ( 1 ) < /xsl:stylesheet> Transformation Results <?xml version="1.0" encoding="utf-8"?> < ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> d. < xsl:if test="@productid='x01-0001'"> <xsl:copy-of /> < /xsl:if>
4) Select the correct description that fits in (1) of XSLT Stylesheet to obtain the transformation result X01-0001X01-0002X01-0003X01-0004 when XSLT Stylesheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> < ProductList> <ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> <ProductName ProductID="X01-0002">XML SchemaProblemSet2</ProductName> <ProductName ProductID="X01-0003">XSLTProblemSet1</ProductName> <ProductName ProductID="X01-0004">XSLTProblemSet2</ProductName> < /ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> < xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:apply-templates select="productlist/productname" /> <xsl:template match="productname"> ( 1 ) < /xsl:stylesheet> Transformation Results X01-0001X01-0002X01-0003X01-0004 a. <xsl:value-of select="productlist/productname/@productid" />
4) Select the correct description that fits in (1) of XSLT Stylesheet to obtain the transformation result X01-0001X01-0002X01-0003X01-0004 when XSLT Stylesheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> < ProductList> <ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> <ProductName ProductID="X01-0002">XML SchemaProblemSet2</ProductName> <ProductName ProductID="X01-0003">XSLTProblemSet1</ProductName> <ProductName ProductID="X01-0004">XSLTProblemSet2</ProductName> < /ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> < xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:apply-templates select="productlist/productname" /> <xsl:template match="productname"> ( 1 ) < /xsl:stylesheet> Transformation Results X01-0001X01-0002X01-0003X01-0004 b. < xsl:value-of select="productlist/productname/productid" />
4) Select the correct description that fits in (1) of XSLT Stylesheet to obtain the transformation result X01-0001X01-0002X01-0003X01-0004 when XSLT Stylesheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> < ProductList> <ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> <ProductName ProductID="X01-0002">XML SchemaProblemSet2</ProductName> <ProductName ProductID="X01-0003">XSLTProblemSet1</ProductName> <ProductName ProductID="X01-0004">XSLTProblemSet2</ProductName> < /ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> < xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:apply-templates select="productlist/productname" /> <xsl:template match="productname"> ( 1 ) < /xsl:stylesheet> Transformation Results X01-0001X01-0002X01-0003X01-0004 c. <xsl:value-of select="productid" />
4) Select the correct description that fits in (1) of XSLT Stylesheet to obtain the transformation result X01-0001X01-0002X01-0003X01-0004 when XSLT Stylesheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> < ProductList> <ProductName ProductID="X01-0001">XML SchemaProblemSet1</ProductName> <ProductName ProductID="X01-0002">XML SchemaProblemSet2</ProductName> <ProductName ProductID="X01-0003">XSLTProblemSet1</ProductName> <ProductName ProductID="X01-0004">XSLTProblemSet2</ProductName> < /ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> < xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:apply-templates select="productlist/productname" /> <xsl:template match="productname"> ( 1 ) < /xsl:stylesheet> Transformation Results X01-0001X01-0002X01-0003X01-0004 d. < xsl:value-of select="@productid" />
5) Select which of the following is the correct XSLT stylesheet to output Transformation Results sorted by the Password attribute value for the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <UserList> <UserID Password="xxxxxx" Delete="1">User01</UserID> <UserID Password="zzzzzz" Delete="0">User02</UserID> <UserID Password="xyzxyz" Delete="0">User03</UserID> <UserID Password="yyyyyy" Delete="0">User04</UserID> </UserList> Transformation Results User01/User03/User04/User02/ a. <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:sort select="@password" data-type="text" /> <xsl:apply-templates select="userlist/userid" /> <xsl:template match="userid"> <xsl:value-of select="." /><xsl:text>/</xsl:text> </xsl:stylesheet>
5) Select which of the following is the correct XSLT stylesheet to output Transformation Results sorted by the Password attribute value for the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <UserList> <UserID Password="xxxxxx" Delete="1">User01</UserID> <UserID Password="zzzzzz" Delete="0">User02</UserID> <UserID Password="xyzxyz" Delete="0">User03</UserID> <UserID Password="yyyyyy" Delete="0">User04</UserID> </UserList> Transformation Results User01/User03/User04/User02/ b. <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:apply-templates select="userlist/userid" /> <xsl:sort select="@password" data-type="text" /> <xsl:template match="userid"> <xsl:value-of select="." /><xsl:text>/</xsl:text> </xsl:stylesheet>
5) Select which of the following is the correct XSLT stylesheet to output Transformation Results sorted by the Password attribute value for the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <UserList> <UserID Password="xxxxxx" Delete="1">User01</UserID> <UserID Password="zzzzzz" Delete="0">User02</UserID> <UserID Password="xyzxyz" Delete="0">User03</UserID> <UserID Password="yyyyyy" Delete="0">User04</UserID> </UserList> Transformation Results User01/User03/User04/User02/ c. <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:apply-templates select="userlist/userid"> <xsl:sort select="@password" data-type="text" /> </xsl:apply-templates> <xsl:template match="userid"> <xsl:value-of select="." /><xsl:text>/</xsl:text> </xsl:stylesheet>
5) Select which of the following is the correct XSLT stylesheet to output Transformation Results sorted by the Password attribute value for the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <UserList> <UserID Password="xxxxxx" Delete="1">User01</UserID> <UserID Password="zzzzzz" Delete="0">User02</UserID> <UserID Password="xyzxyz" Delete="0">User03</UserID> <UserID Password="yyyyyy" Delete="0">User04</UserID> </UserList> Transformation Results User01/User03/User04/User02/ d. <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:apply-templates select="userlist/userid" /> <xsl:template match="userid"> <xsl:sort select="@password" data-type="text"> <xsl:value-of select="." /><xsl:text>/</xsl:text> </xsl:sort> </xsl:stylesheet>
6) Select which of the following is the correct transformation result when XSLT Stylesheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <ProductList> <Title>XML Series Commemorative Goods</Title> <Product> <ProductName>XML Pen</ProductName> <UnitPrice>200</UnitPrice> </Product> </ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <html> <body> <xsl:apply-templates select="productlist/product"/> <xsl:apply-templates select="productlist/auxiliary"/> </body> </html> <xsl:template match="/productlist/product"> - ProductName:<xsl:value-of select="productname" /><br/> - UnitPrice:<xsl:value-of select="unitprice" />$<br/> <xsl:template match="productlist/product"> ProductName:<xsl:value-of select="productname" /><br/> UnitPrice:<xsl:value-of select="unitprice" />USD<br/> <xsl:template match="auxiliary"> Auxiliary:<br/> <xsl:value-of select="." /><br/> </xsl:stylesheet> a. <?xml version="1.0" encoding="utf-8"?> <html> <body> - ProductName:XML Pen<br> - UnitPrice:200USD<br> </body> </html>
6) Select which of the following is the correct transformation result when XSLT Stylesheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <ProductList> <Title>XML Series Commemorative Goods</Title> <Product> <ProductName>XML Pen</ProductName> <UnitPrice>200</UnitPrice> </Product> </ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <html> <body> <xsl:apply-templates select="productlist/product"/> <xsl:apply-templates select="productlist/auxiliary"/> </body> </html> <xsl:template match="/productlist/product"> - ProductName:<xsl:value-of select="productname" /><br/> - UnitPrice:<xsl:value-of select="unitprice" />$<br/> <xsl:template match="productlist/product"> ProductName:<xsl:value-of select="productname" /><br/> UnitPrice:<xsl:value-of select="unitprice" />USD<br/> <xsl:template match="auxiliary"> Auxiliary:<br/> <xsl:value-of select="." /><br/> </xsl:stylesheet> b. <?xml version="1.0" encoding="utf-8"?> <html> <body> ProductName:XML Pen<br> UnitPrice:200USD<br> </body> </html>
6) Select which of the following is the correct transformation result when XSLT Stylesheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <ProductList> <Title>XML Series Commemorative Goods</Title> <Product> <ProductName>XML Pen</ProductName> <UnitPrice>200</UnitPrice> </Product> </ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <html> <body> <xsl:apply-templates select="productlist/product"/> <xsl:apply-templates select="productlist/auxiliary"/> </body> </html> <xsl:template match="/productlist/product"> - ProductName:<xsl:value-of select="productname" /><br/> - UnitPrice:<xsl:value-of select="unitprice" />$<br/> <xsl:template match="productlist/product"> ProductName:<xsl:value-of select="productname" /><br/> UnitPrice:<xsl:value-of select="unitprice" />USD<br/> <xsl:template match="auxiliary"> Auxiliary:<br/> <xsl:value-of select="." /><br/> </xsl:stylesheet> c. <?xml version="1.0" encoding="utf-8"?> <html> <body> - ProductName:XML Pen<br> - UnitPrice:200USD<br> Auxiliary:<br> </body> </html>
6) Select which of the following is the correct transformation result when XSLT Stylesheet is applied to the given XML Document. XML Document <?xml version="1.0" encoding="utf-8"?> <ProductList> <Title>XML Series Commemorative Goods</Title> <Product> <ProductName>XML Pen</ProductName> <UnitPrice>200</UnitPrice> </Product> </ProductList> XSLT Stylesheet <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <html> <body> <xsl:apply-templates select="productlist/product"/> <xsl:apply-templates select="productlist/auxiliary"/> </body> </html> <xsl:template match="/productlist/product"> - ProductName:<xsl:value-of select="productname" /><br/> - UnitPrice:<xsl:value-of select="unitprice" />$<br/> <xsl:template match="productlist/product"> ProductName:<xsl:value-of select="productname" /><br/> UnitPrice:<xsl:value-of select="unitprice" />USD<br/> <xsl:template match="auxiliary"> Auxiliary:<br/> <xsl:value-of select="." /><br/> </xsl:stylesheet> d. <?xml version="1.0" encoding="utf-8"?> <html> <body> ProductName:XML Pen<br> UnitPrice:200USD<br> Auxiliary:<br> </body> </html>
Πηγές / Acknowledgements Βιβλιογραφία http://www.w3schools.com/xml/ http://www.w3.org/xml/ http://www.xml.com/ http://www.xml.org/