JRT: Difference between revisions
From ICO wiki
Jump to navigationJump to search
No edit summary |
|||
Line 386: | Line 386: | ||
<?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | <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" | xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> | ||
> | |||
<xsl:output method="xml" indent="yes"/> | <xsl:output method="xml" indent="yes"/> | ||
<xsl:template match="/"> | <xsl:template match="/"> | ||
<main> | <main> |
Revision as of 22:47, 20 March 2017
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> <h2>JRT Fitness Studio prices for classes</h2> <table border="1"> <xsl:apply-templates/> </table> <br/> <h2>Registered users</h2> <table border="1"> <tr bgcolor="#9acd32"> <th></th> <th>First name</th> <th>Last name</th> <th>Born</th> <th>Sex</th> </tr> <xsl:for-each select="users/user"> <xsl:sort select="lastName"/> <tr> <td><xsl:value-of select="firstName"/></td> <td><xsl:value-of select="lastName"/></td> <td><xsl:value-of select="born"/></td> <xsl:choose> <xsl:when test="sex = W"> <td bgcolor="#ff00ff"> <xsl:value-of select="sex"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="sex"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> <xsl:template match=" users/subscriptions/subscription | users/subscriptions/subscription/prices/price[@type='gold'] | users/subscriptions/subscription/prices/price[@type='silver'] | users/subscriptions/subscription/prices/price[@type='standard']"> <tr> <xsl:apply-templates/> </tr> </xsl:template> <xsl:template match="price"> <td> <xsl:value-of select="."/> </td> </xsl:template> </xsl:stylesheet>
XSLT 3
<?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="/"> <main> <xsl:for-each select="users/subscriptions/subscription"> <subscription> <xsl:attribute name="id"> <xsl:value-of select="position()"/> </xsl:attribute> <xsl:attribute name="name"> <xsl:value-of select="@name"/> </xsl:attribute> <xsl:variable name="currentSubscription" select="@name" /> <usersWithPrices> <xsl:for-each select="/users/user"> <xsl:variable name="currentUser" select="."></xsl:variable> <xsl:for-each select="subscriptions/subscription"> <xsl:variable name="sub" select="."/> <xsl:if test="$sub = $currentSubscription"> <userWithPrice> <user> <xsl:attribute name="id"> <xsl:value-of select="$currentUser/@id"/> </xsl:attribute> <xsl:value-of select="$currentUser/firstName"/> <xsl:text> </xsl:text> <xsl:value-of select="$currentUser/lastName"/> </user> <xsl:variable name="status" select="$currentUser/@status"/> <xsl:for-each select="/users/subscriptions/subscription"> <xsl:variable name="subscr" select="."></xsl:variable> <xsl:for-each select="$subscr/prices/price"> <xsl:if test="$subscr/@name = $currentSubscription"> <xsl:variable name="curObj" select="."/> <xsl:if test="$curObj/@type = $status"> <price> <xsl:attribute name="currency"> <xsl:value-of select="$curObj/@currency"/> </xsl:attribute> <xsl:attribute name="type"> <xsl:value-of select="$curObj/@type"/> </xsl:attribute> <xsl:value-of select="."/> </price> </xsl:if> </xsl:if> </xsl:for-each> </xsl:for-each> </userWithPrice> </xsl:if> <xsl:value-of select="@status"/> </xsl:for-each> </xsl:for-each> </usersWithPrices> </subscription> </xsl:for-each> </main> </xsl:template>
</xsl:stylesheet>
Näidis
<?xml version="1.0" encoding="utf-8"?> <main>
<subscription id="1" name="Balance"> <usersWithPrices> <userWithPrice> <user id="1">Peeter Banaan</user> <price currency="EUR" type="gold">39.99</price> </userWithPrice> <userWithPrice> <user id="2">Merlin Kuusk</user> <price currency="EUR" type="silver">44.99</price> </userWithPrice> <userWithPrice> <user id="6">Georg Karu</user> <price currency="EUR" type="standard">50.99</price> </userWithPrice> </usersWithPrices> </subscription> <subscription id="2" name="Gym"> <usersWithPrices> <userWithPrice> <user id="1">Peeter Banaan</user> <price currency="EUR" type="gold">69.99</price> </userWithPrice> <userWithPrice> <user id="4">Peeter Tamm</user> <price currency="EUR" type="gold">69.99</price> </userWithPrice> <userWithPrice> <user id="6">Georg Karu</user> <price currency="EUR" type="standard">89.99</price> </userWithPrice> </usersWithPrices> </subscription> <subscription id="3" name="BodyPump"> <usersWithPrices> <userWithPrice> <user id="2">Merlin Kuusk</user> <price currency="EUR" type="silver">49.99</price> </userWithPrice> <userWithPrice> <user id="4">Peeter Tamm</user> <price currency="EUR" type="gold">44.99</price> </userWithPrice> <userWithPrice> <user id="7">Liisa Leppmaa</user> <price currency="EUR" type="standard">55.99</price> </userWithPrice> </usersWithPrices> </subscription> <subscription id="4" name="Yoga"> <usersWithPrices> <userWithPrice> <user id="1">Peeter Banaan</user> <price currency="EUR" type="gold">39.99</price> </userWithPrice> <userWithPrice> <user id="3">Maarika Tamm</user> <price currency="EUR" type="gold">39.99</price> </userWithPrice> </usersWithPrices> </subscription> <subscription id="5" name="HotYoga"> <usersWithPrices> <userWithPrice> <user id="3">Maarika Tamm</user> <price currency="EUR" type="gold">49.99</price> </userWithPrice> <userWithPrice> <user id="7">Liisa Leppmaa</user> <price currency="EUR" type="standard">55.99</price> </userWithPrice> </usersWithPrices> </subscription>
</main>