JRT
Meeskond
Riho Uusjärv
Jevgeni Gavrilov
Tiit Kuuskmäe
Blog
03.19.2017 - Meeskonna loomine, teema välja mõtlemine, XML, XSD ja XSLT koostamine
Tööd
XML (pole veel valmis)
Teema
Spordisaalis on erinevad trennid, milles käivad erinevad isikud. XSLT jaoks siis teeme erinevad valitud filtreeringud
XML
<?xml version="1.0" encoding="utf-8" ?> <users> <subscriptions> <subscription name="Balance"> <prices> <price type="silver" currency="EUR">44.99</price> <price type="gold" currency="EUR">39.99</price> <price type="standard" currency="EUR">50.99</price> </prices> </subscription> <subscription name="Gym"> <prices> <price type="gold" currency="EUR">69.99</price> <price type="silver" currency="EUR">79.99</price> <price type="standard" currency="EUR">89.99</price> </prices> </subscription> <subscription name="BodyPump"> <prices> <price type="gold" currency="EUR">44.99</price> <price type="silver" currency="EUR">49.99</price> <price type="standard" currency="EUR">55.99</price> </prices> </subscription> <subscription name="Yoga"> <prices> <price type="gold" currency="EUR">39.99</price> <price type="silver" currency="EUR">42.99</price> <price type="standard" currency="EUR">45.99</price> </prices> </subscription> <subscription name="HotYoga"> <prices> <price type="gold" currency="EUR">49.99</price> <price type="silver" currency="EUR">52.99</price> <price type="standard" currency="EUR">55.99</price> </prices> </subscription> </subscriptions> <user id="1" status="gold"> <firstName><![CDATA[Peeter]]></firstName> <lastName><![CDATA[Banaan]]></lastName> <born><![CDATA[11.12.2000]]></born> <sex><![CDATA[M]]></sex> <subscriptions> <subscription expires="2017-05-11"><![CDATA[Balance]]></subscription> <subscription expires="2017-08-26"><![CDATA[Gym]]></subscription> <subscription expires="2017-09-01"><![CDATA[Yoga]]></subscription> </subscriptions> <contacts> <contact type="phone"><![CDATA[55665566]]></contact> <contact type="email"><![CDATA[peeter@gmail.ee]]></contact> <contact type="skype"><![CDATA[PeeterB]]></contact> </contacts> </user> <user id="2" status="silver"> <firstName><![CDATA[Merlin]]></firstName> <lastName><![CDATA[Kuusk]]></lastName> <born><![CDATA[11.07.1997]]></born> <sex><![CDATA[W]]></sex> <subscriptions> <subscription expires="2017-05-13"><![CDATA[BodyPump]]></subscription> <subscription expires="2017-09-11"><![CDATA[Balance]]></subscription> </subscriptions> <contacts> <contact type="phone"><![CDATA[5123123]]></contact> </contacts> </user> <user id="3" status="gold"> <firstName><![CDATA[Maarika]]></firstName> <lastName><![CDATA[Tamm]]></lastName> <born><![CDATA[05.07.1999]]></born> <sex><![CDATA[W]]></sex> <subscriptions> <subscription expires="2017-08-11"><![CDATA[Yoga]]></subscription> <subscription expires="2017-11-23"><![CDATA[HotYoga]]></subscription> </subscriptions> <contacts> <contact type="email"><![CDATA[maarika@gmail.com]]></contact> </contacts> </user> <user id="4" status="gold"> <firstName><![CDATA[Peeter]]></firstName> <lastName><![CDATA[Tamm]]></lastName> <born><![CDATA[22.03.2000]]></born> <sex><![CDATA[M]]></sex> <subscriptions> <subscription expires="2017-05-13"><![CDATA[BodyPump]]></subscription> <subscription expires="2017-05-13"><![CDATA[Gym]]></subscription> </subscriptions> <contacts> <contact type="phone"><![CDATA[55588899]]></contact> <contact type="email"><![CDATA[PeeterT@gmail.com]]></contact> </contacts> </user> <user id="5" status="silver"> <firstName><![CDATA[Mihkel]]></firstName> <lastName><![CDATA[Koopov]]></lastName> <born><![CDATA[15.06.1994]]></born> <sex><![CDATA[M]]></sex> <contacts> <contact type="phone"><![CDATA[55588877]]></contact> <contact type="skype"><![CDATA[MKoopov]]></contact> </contacts> </user> <user id="6" status="standard"> <firstName><![CDATA[Georg]]></firstName> <lastName><![CDATA[Karu]]></lastName> <born><![CDATA[03.03.1994]]></born> <sex><![CDATA[M]]></sex> <subscriptions> <subscription expires="2017-12-17"><![CDATA[Balance]]></subscription> <subscription expires="2017-09-01"><![CDATA[Gym]]></subscription> </subscriptions> </user> <user id="7" status="standard"> <firstName><![CDATA[Liisa]]></firstName> <lastName><![CDATA[Leppmaa]]></lastName> <born><![CDATA[15.06.1991]]></born> <sex><![CDATA[W]]></sex> <subscriptions> <subscription expires="2017-09-11"><![CDATA[BodyPump]]></subscription> <subscription expires="2017-07-10"><![CDATA[HotYoga]]></subscription> </subscriptions> <contacts> <contact type="phone"><![CDATA[55512377]]></contact> <contact type="skype"><![CDATA[LLee]]></contact> </contacts> </user> </users>
XML schema (XSD)
<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="users"> <xs:complexType> <xs:sequence> <xs:element name="subscriptions"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="subscription"> <xs:complexType> <xs:sequence> <xs:element name="prices"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="price"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:decimal"> <xs:attribute name="type" type="xs:string" use="required" /> <xs:attribute name="currency" type="xs:string" use="required" /> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="name" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element maxOccurs="unbounded" name="user"> <xs:complexType> <xs:sequence> <xs:choice maxOccurs="unbounded"> <xs:element name="firstName" type="xs:string" /> <xs:element name="lastName" type="xs:string" /> <xs:element name="subscriptions"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="subscription"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="expires" type="xs:date" use="required" /> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="contacts"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="contact"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="type" type="xs:string" use="required" /> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="born" type="xs:string" /> <xs:element name="sex" type="xs:string" /> </xs:choice> </xs:sequence> <xs:attribute name="id" type="xs:int" use="required" /> <xs:attribute name="status" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
XSLT 1
Kuvab inimeste nime, liikme staatuse, treeningud koos hindedega
<?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="html" indent="yes"/> <xsl:template match="/"> <html> <head> <title> Workout: </title> </head> <body> <h2>People list with workout and price:</h2> <xsl:for-each select="/users/user"> <xsl:text>Name: </xsl:text> <xsl:value-of select="firstName"/> <xsl:text> </xsl:text> <xsl:value-of select="lastName"/> <br></br> <xsl:text>Member status: </xsl:text> <xsl:variable name="Status" select="@status"/> <xsl:value-of select="@status"/> <br></br> <xsl:if test="subscriptions/subscription != ''"> <xsl:text>Workouts and prices: </xsl:text> <ul> <xsl:for-each select="subscriptions/subscription"> <li> <xsl:text> </xsl:text> <xsl:variable name="SelectedSubscription" select="translate(text(), ' ', '')"/> <xsl:for-each select="/users/subscriptions/subscription"> <xsl:variable name="Subscription" select="@name"/> <xsl:if test="$Subscription= $SelectedSubscription"> <xsl:for-each select="prices/price"> <xsl:if test="$Status = @type"> <xsl:value-of select="$Subscription"/> <xsl:text>: </xsl:text> <xsl:value-of select="."/> <xsl:value-of select="@currency"/> </xsl:if> </xsl:for-each> </xsl:if> </xsl:for-each> </li> </xsl:for-each> </ul> </xsl:if> <br></br> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
Näidis
XSLT 2
<?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="html" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<html> <head> <title>XSLT 2</title> </head>
<body>
JRT Fitness Studio prices for classes
<xsl:for-each select="users/subscriptions"><xsl:for-each select="users/subscriptions/subscription/prices/price"> <xsl:if test="price != "><xsl:apply-templates/> </xsl:if> </xsl:for-each> </xsl:for-each>
Class name | Gold package | Silver package | Standard package |
---|---|---|---|
<xsl:value-of select="subscrition"/> | |||
Registered users
<xsl:for-each select="users/user"> <xsl:sort select="lastName"/><xsl:choose> <xsl:when test="sex = W">
</xsl:when> <xsl:otherwise>
</xsl:otherwise> </xsl:choose></xsl:for-each>
First name | Last name | Born | Sex | |
---|---|---|---|---|
<xsl:value-of select="firstName"/> | <xsl:value-of select="lastName"/> | <xsl:value-of select="born"/> | <xsl:value-of select="sex"/> | <xsl:value-of select="sex"/> |
</body> </html>
</xsl:template>
<xsl:template match="users/subscriptions/subscription/prices">
<xsl:apply-templates select="price"/>
</xsl:template> <xsl:template match="$type = gold"> <xsl:value-of select="."/> </xsl:template> <xsl:template match="$type = silver"> <xsl:value-of select="."/> </xsl:template> <xsl:template match="$type = standard"> <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet>