JRT: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Ruusjarv (talk | contribs)
Ruusjarv (talk | contribs)
Line 7: Line 7:
= Blog =
= Blog =


19.03.2017 - Meeskonna loomine, teema välja mõtlemine, XML, XSD ja XSLT koostamine
19.03.2017 - Meeskonna loomine, teema välja mõtlemine, XML, XSD ja XSLT koostamine<br>
20.03.2017 - Teine XSLT koostamine ja valmis
20.03.2017 - Teine XSLT koostamine ja valmis



Revision as of 08:07, 21 March 2017

Meeskond

Riho Uusjärv
Jevgeni Gavrilov
Tiit Kuuskmäe

Blog

19.03.2017 - Meeskonna loomine, teema välja mõtlemine, XML, XSD ja XSLT koostamine
20.03.2017 - Teine XSLT koostamine ja valmis

Tööd

XML

Teema

Spordisaalis on erinevad trennid, milles käivad erinevad isikud. XSLT jaoks siis teeme erinevad valitud filtreeringud

Lae failid alla

Lae failid alla.

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="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>

Retsensioonid