Meeskond Tudengikalender
From ICO wiki
Meeskond "Tudengikalender"
Meeskonna liikmed:
- Taavi Sildeberg
- Kunnar Kukk
Kodutöö XML (11. märts)
XML-fail hoiab andmeid ainete, tudengite ning tudengiga seotud kodutööde kohta.
Database.xml
<?xml version="1.0" encoding="utf-8" ?> <database> <users> <user id="1908934" username="taavis"> <fullname>Taavi Sildeberg</fullname> <email>taavi@sildeberg.eu</email> <mobile>+3725058624</mobile> </user> <user id="43" username="kunnark"> <fullname>Kunnar Kukk</fullname> <email>kunnar.kukk@gmail.com</email> <mobile>+37256299030</mobile> </user> <user id="433" username="johnd"> <fullname>Jhon Doe</fullname> <email></email> <mobile>57260989</mobile> </user> </users> <subjects> <subject id="1" userId="433"> <name><![CDATA[Võrgurakendused II]]></name> <schedule from="2014-02-01" to="2014-05-01"></schedule> <homeworks> <homework id="1" deadline="2014-03-03T20:00:00Z"> <name><![CDATA[XML osa]]></name> <description><![CDATA[Korralik xml fail ja lisaks on vaja ka kaks transformatsiooni]]></description> <comment><![CDATA[Oh krt, ei ole üldse veel sellega alusatnud. Ja kas mitte keegi tiimist ei pidanud seda juba tegema]]></comment> <status>open</status> </homework> <homework id="2" deadline="2014-05-03T20:00:00Z"> <name><![CDATA[Retsensioonid]]></name> <description><![CDATA[Retsensioon ja veel üks retsensioon]]></description> <comment><![CDATA[Oh krt, ei ole üldse veel sellega alusatnud. Ja kas mitte keegi tiimist ei pidanud seda juba tegema]]></comment> <status>open</status> </homework> <homework id="3" deadline="2014-04-05T20:00:00Z"> <name><![CDATA[Web service for .NET]]></name> <description><![CDATA[Veebiteenus ASP.dot neti jaoks, kena UI ja midagi veel]]></description> <comment><![CDATA[Esialgne plaan olemas, vaja veel data kihi jaoks asjad kokku leppida]]></comment> <status>in-progress</status> </homework> <homework id="4" deadline="2014-02-04T20:00:00Z"> <name><![CDATA[Web asjake]]></name> <description><![CDATA[Praktikumi näite käimaajamine]]></description> <comment><![CDATA[]]></comment> <status>done</status> </homework> </homeworks> </subject> <subject id="2" userId="43" > <name><![CDATA[JAVA aine]]></name> <schedule from="2014-02-01" to="2014-03-01"></schedule> <homeworks> <homework id="1" deadline="2014-02-10T15:30:00Z"> <name><![CDATA[Kodutöö]]></name> <description><![CDATA[Paar progemisülesannet]]></description> <comment><![CDATA[Õnneks juba esitatud]]></comment> <status>open</status> </homework> </homeworks> </subject> <subject id="3" userId="1908934"> <name><![CDATA[Majanduse aine]]></name> <schedule from="2014-02-01" to="2014-06-01"></schedule> <homeworks> <homework id="1" deadline="2014-02-15T15:30:00Z"> <name><![CDATA[Kontrolltöö]]></name> <description><![CDATA[KT esimese 4 peatüki peale]]></description> <comment><![CDATA[]]></comment> <status>open</status> </homework> </homeworks> </subject> <subject id="4" userId="43"> <name><![CDATA[Algoritmika]]></name> <schedule from="2014-02-01" to="2014-06-01"></schedule> <homeworks> <homework id="1" deadline="2014-02-15T15:30:00Z"> <name><![CDATA[Kodune analüüsi üleanne]]></name> <description><![CDATA[Vaata materjaöle wikist]]></description> <comment><![CDATA[]]></comment> <status>open</status> </homework> </homeworks> </subject> </subjects> </database>
Skeemifail: Database.xsd
<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- Email type, validates that value is correct email or empty value, if user has not defined anything --> <xs:simpleType name="emailAddress"> <xs:restriction base="xs:string"> <xs:pattern value="|^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"/> </xs:restriction> </xs:simpleType> <!-- Homework status custom type. Restricts values only for defined values --> <xs:simpleType name="homeworkStatus"> <xs:restriction base="xs:string"> <xs:enumeration value="open"/> <xs:enumeration value="in-progress"/> <xs:enumeration value="done"/> </xs:restriction> </xs:simpleType> <!-- Mobile number custom type. Restricts mobile numbers to valid numbers, should work also with country code --> <xs:simpleType name="mobileNumber"> <xs:restriction base="xs:string"> <xs:pattern value="^(\+|\d)[0-9]{7,16}$"/> </xs:restriction> </xs:simpleType> <xs:element name="database"> <xs:complexType> <xs:sequence> <!-- Users section, holds list of user entities --> <xs:element name="users"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="user"> <xs:complexType> <xs:sequence> <xs:element name="fullname" type="xs:string" /> <xs:element name="email" type="emailAddress" /> <xs:element name="mobile" type="mobileNumber" /> </xs:sequence> <xs:attribute name="id" type="xs:unsignedInt" use="required"/> <xs:attribute name="username" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> <!-- Unique constaraint for user id-s, so that user id will be unique for entire database --> <xs:unique name="unique_user_id"> <xs:selector xpath="user"/> <xs:field xpath="@id"/> </xs:unique> </xs:element> <!-- Subjects section, holds list of subject entities --> <xs:element name="subjects"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="subject"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string" /> <xs:element name="schedule"> <xs:complexType> <xs:attribute name="from" type="xs:date" use="required"/> <xs:attribute name="to" type="xs:date" use="required" /> </xs:complexType> </xs:element> <xs:element name="homeworks"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="homework"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string" /> <xs:element name="description" type="xs:string" /> <xs:element name="comment" type="xs:string" nillable="true"/> <xs:element name="status" type="homeworkStatus" default="open"/> </xs:sequence> <xs:attribute name="id" type="xs:unsignedByte" use="required" /> <xs:attribute name="deadline" type="xs:dateTime" use="required"> </xs:attribute> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> <!-- Unique constarant for homework id-s, so that homework id will be unique for the current subject, where it belongs --> <xs:unique name="unique_homework_id"> <xs:selector xpath="homework"/> <xs:field xpath="@id"/> </xs:unique> </xs:element> </xs:sequence> <xs:attribute name="id" type="xs:unsignedInt" use="required" /> <xs:attribute name="userId" type="xs:unsignedInt" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> <!-- Unique constarant for subject id-s, so that subject id will be unique for entire database --> <xs:unique name="unique_subject_id"> <xs:selector xpath="subject"/> <xs:field xpath="@id"/> </xs:unique> </xs:element> </xs:sequence> </xs:complexType> <!-- User id key definition --> <xs:key name="UserIdNumber"> <xs:selector xpath="./users/user" /> <xs:field xpath="@id" /> </xs:key> <!-- User id key referenc, used for validating userId-s in subjects section, so that subjects have only valid userId-s --> <xs:keyref name="UserIdNumberRef" refer="UserIdNumber"> <xs:selector xpath="./subjects/subject" /> <xs:field xpath="@userId" /> </xs:keyref> </xs:element> </xs:schema>
Transformatsioon (xml->html): Overview.xslt
Kuvatakse kasutaja, temaga seotud ained ning kodutööde staatused
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" > <xsl:decimal-format name="percentFormat" decimal-separator="." grouping-separator="," infinity="INFINITY" minus-sign="-" NaN="0" percent="%" per-mille="m" zero-digit="0" digit="#" pattern-separator=";" /> <xsl:output method="html" indent="yes"/> <xsl:template match="/"> <html lang="en"> <head> <meta charset="utf-8"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>XSL Transformation Homework</title> <!-- Bootstrap --> <link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <div class="container"> <div class="page-header"> <h1> XSLT transformatsioon <small> Inimesed, õppeainded ja nende kodutööd</small> </h1> </div> <div class="panel panel-default"> <div class="panel-body"> <xsl:for-each select="//users/user"> <xsl:variable name="currentUserId" select="./@id"/> <h1> <xsl:value-of select="fullname"></xsl:value-of> </h1> <xsl:for-each select ="//subject[@userId=$currentUserId]"> <xsl:variable name="homeworksList" select="./homeworks/homework"></xsl:variable> <xsl:variable name="doneHomeworksList" select="./homeworks/homework[status='done']"></xsl:variable> <xsl:variable name="openHomeworksList" select="./homeworks/homework[status='open']"></xsl:variable> <xsl:variable name="inProgressHomeworksList" select="./homeworks/homework[status='in-progress']"></xsl:variable> <div class="panel panel-info"> <div class="panel-heading"> <h3 class="panel-title"> <xsl:value-of select="name"/> </h3> </div> <div class="panel-body"> <h4>Aine kodutööde progress</h4> <div class="progress"> <xsl:element name="div"> <xsl:variable name="valueString" select="format-number(count($doneHomeworksList) div count($homeworksList), '###.#%', 'percentFormat')"/> <xsl:attribute name="class">progress-bar progress-bar-success</xsl:attribute> <xsl:attribute name="style"> <xsl:value-of select="concat('width:', $valueString)"/> </xsl:attribute> Valmis </xsl:element> <xsl:element name="div"> <xsl:variable name="valueString" select="format-number(count($inProgressHomeworksList) div count($homeworksList), '###.#%', 'percentFormat')"/> <xsl:attribute name="class">progress-bar progress-bar-warning</xsl:attribute> <xsl:attribute name="style"> <xsl:value-of select="concat('width:', $valueString)"/> </xsl:attribute> Pooleli </xsl:element> <xsl:element name="div"> <xsl:variable name="valueString" select="format-number(count($openHomeworksList) div count($homeworksList), '###.#%', 'percentFormat')"/> <xsl:attribute name="class">progress-bar progress-bar-danger</xsl:attribute> <xsl:attribute name="style"> <xsl:value-of select="concat('width:', $valueString)"/> </xsl:attribute> Alustamata </xsl:element> </div> <h4>Aine kodutööde nimekiri</h4> <xsl:for-each select="$homeworksList"> <ul> <li> <xsl:value-of select="name"/> </li> </ul> </xsl:for-each> </div> </div> </xsl:for-each> </xsl:for-each> </div> </div> </div> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> </body> </html> </xsl:template> </xsl:stylesheet>
Transformatsioon (xml->xml): DatabaseXML.xslt
Näidatakse nö kooli vaadet, kus on kuvatud kõik ained ning ainega seotud kodutööd.
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <subjects> <xsl:for-each select="database/subjects/subject"> <subject> <xsl:copy-of select="name"></xsl:copy-of> <xsl:copy-of select="schedule"></xsl:copy-of> <homeworks> <xsl:for-each select="homeworks"> <xsl:for-each select="homework"> <homework> <xsl:attribute name="deadline"> <xsl:value-of select="@deadline"/> </xsl:attribute> <xsl:copy-of select="name"/> <xsl:copy-of select="description"/> </homework> </xsl:for-each> </xsl:for-each> </homeworks> </subject> </xsl:for-each> </subjects> </xsl:template> </xsl:stylesheet>