Team SPOT: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Line 15: Line 15:
=== XML ===
=== XML ===


<nowiki>
{{Vaata koodi|collapsible=yes|<nowiki>{{ombox|text=
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="trainingsToHtml.xslt"?>
<?xml-stylesheet type="text/xsl" href="trainingsToHtml.xslt"?>
Line 236: Line 236:
     <VideoUrl>https://www.youtube.com/embed/-ZB6XIkfxnQ</VideoUrl>
     <VideoUrl>https://www.youtube.com/embed/-ZB6XIkfxnQ</VideoUrl>
   </Training>
   </Training>
</Trainings>
</Trainings>}}
</nowiki>
</nowiki>}}


=== XSD ===
=== XSD ===

Revision as of 15:07, 20 March 2017

Kodutöö aines "Võrgurakendused II: hajussüsteemide ehitamine"

Projekti kodu

Liikmed

  • Sigrid Pachel
  • Oliver Tiks

Idee

XML / XSD / XSLT

XML

Template:Vaata koodi

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="Trainings">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Styles">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="unbounded" name="Style">
                <xs:complexType>
                  <xs:simpleContent>
                    <xs:extension base="xs:string">
                      <xs:attribute name="Id" type="xs:int" use="required" />
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
          <xs:unique name="UniqueStyleId">
            <xs:selector xpath="Style"/>
            <xs:field xpath="@Id"/>
          </xs:unique>
        </xs:element>
        <xs:element name="Instructors">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="unbounded" name="Instructor">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="Name" type="xs:string"/>
                  </xs:sequence>
                  <xs:attribute name="Id" type="xs:int" use="required" />
                  <xs:attribute name="Rating" type="xs:decimal" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
          <xs:unique name="UniqueInstructorId">
            <xs:selector xpath="Instructor"/>
            <xs:field xpath="@Id"/>
          </xs:unique>
        </xs:element>
        <xs:element name="Venues">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="unbounded" name="Venue">
                <xs:complexType>
                  <xs:simpleContent>
                    <xs:extension base="xs:string">
                      <xs:attribute name="Id" type="xs:int" use="required" />
                      <xs:attribute name="GroupSize" type="xs:int" use="required" />
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
          <xs:unique name="UniqueVenueId">
            <xs:selector xpath="Venue"/>
            <xs:field xpath="@Id"/>
          </xs:unique>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="Training">
          <xs:complexType>
            <xs:all>
              <xs:element name="Name" type="xs:string" />
              <xs:element name="Description" type="xs:string" />
              <xs:element name="Styles">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="Style">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:string">
                            <xs:attribute name="Id" type="xs:int" use="required" />
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="Schedule">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="ScheduleItem">
                      <xs:complexType>
                        <xs:all>
                          <xs:element  maxOccurs="1" name="Time">
                            <xs:complexType>
                              <xs:simpleContent>
                                <xs:extension base="xs:dateTime">
                                  <xs:attribute name="Duration" type="xs:duration" use="required" />
                                </xs:extension>
                              </xs:simpleContent>
                            </xs:complexType>
                          </xs:element>
                          <xs:element name="Instructors">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element maxOccurs="unbounded" name="Instructor">
                                  <xs:complexType>
                                    <xs:simpleContent>
                                      <xs:extension base="xs:string">
                                        <xs:attribute name="Id" type="xs:int" use="required" />
                                      </xs:extension>
                                    </xs:simpleContent>
                                  </xs:complexType>
                                </xs:element>
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>
                          <xs:element minOccurs="0" maxOccurs="1" name="Comment" type="xs:string" />
                        </xs:all>
                        <xs:attribute name="Id" type="xs:int" use="required" />
                        <xs:attribute name="VenueId" type="xs:int" use="required" />
                        <xs:attribute name="GroupSize" type="xs:int" use="optional" />
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="VideoUrl" type="xs:string" />
            </xs:all>
            <xs:attribute name="Id" type="xs:int" use="required" />
            <xs:attribute name="Licence" type="xs:string" use="optional" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
    <xs:unique name="UniqueTrainingId">
      <xs:selector xpath="Training"/>
      <xs:field xpath="@Id"/>
    </xs:unique>
    <xs:unique name="UniqueScheduleItemId">
      <xs:selector xpath="Training/Schedule/ScheduleItem"/>
      <xs:field xpath="@Id"/>
    </xs:unique>
  </xs:element>
</xs:schema>

XSLT (html)

<?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" />
  <xsl:template match="/">
    <html>
      <head>
        <title>SuperSportsClub - Trainings</title>
        <style>
          body {
          background:BurlyWood;
          text-align: center;
          }
          .section {
          text-align:left;
          width:1000px;
          padding:20px;
          background:Chocolate;
          margin: auto;
          }
          table, th, td, .section {
          border: 1px solid black;
          }
          th {
          text-align:left;
          padding-left: 10px;
          padding-right: 10px;
          }
          td {
          text-align:center;
          }
          p {
          text-align:justify;
          }
          .description {
          vertical-align:top; 
          padding:10px;
          }
        </style>
      </head>
      <body>
        <h1>Trainings at SuperSportsClub</h1>
        <xsl:for-each select="/Trainings/Styles/Style">
          <xsl:sort select="."/>
          <xsl:variable select="." name="SelectedStyle" />
          <div class="section" >
            <h2>
              <xsl:value-of select="$SelectedStyle" />
            </h2>
            <ul>
              <xsl:for-each select="/Trainings/Training">
                <xsl:sort select="."/>
                <xsl:variable name="Training" select="." />
                <xsl:if test="Styles/Style/@Id = $SelectedStyle/@Id">
                  <li>
                    <h3>
                      <xsl:value-of select="$Training/Name" />
                      <xsl:if test="$Training/@Licence">
                        <xsl:text> (</xsl:text>
                        <xsl:value-of select="$Training/@Licence" />
                        <xsl:text>)</xsl:text>
                      </xsl:if>
                    </h3>
                    <table>
                      <tr>
                        <th>When:</th>
                        <th>Duration:</th>
                        <th>Where:</th>
                        <th>Instructors:</th>
                      </tr>
                      <xsl:for-each select="$Training/Schedule/ScheduleItem">
                        <xsl:sort select="Time"/>
                        <xsl:variable name="StartTime" select="Time"/>
                        <xsl:variable name="Duration" select="$StartTime/@Duration"/>
                        <tr>
                          <td width="150" >
                            <xsl:value-of select="concat(
                                            substring($StartTime, 9, 2), 
                                            '.', 
                                            substring($StartTime, 6, 2), 
                                            '.', 
                                            substring($StartTime, 1, 4),
                                            ' ',
                                            substring($StartTime, 12, 2),
                                            ':',
                                            substring($StartTime, 15, 2))
                                            " />
                            <xsl:if test="Comment">
                              <br/>
                              <div style="color:Green">
                                <xsl:value-of select="Comment"/>
                              </div>
                            </xsl:if>
                          </td>
                          <td width="100">
                            <xsl:value-of select="substring($Duration, 3, 6)" />
                          </td>
                          <td width="150">
                            <xsl:variable name="VenueId" select="@VenueId"/>
                            <xsl:value-of select="/Trainings/Venues/Venue[@Id=$VenueId]" />
                          </td>
                          <td width="250">
                            <xsl:for-each select="Instructors/Instructor">
                              <xsl:variable name="InstructorId" select="@Id"></xsl:variable>
                              <xsl:variable name="SelectedInstructor" select="/Trainings/Instructors/Instructor[@Id=$InstructorId]" />
                              <xsl:value-of select="$SelectedInstructor/Name"/>
                              <xsl:text> (</xsl:text>
                              <xsl:value-of select="$SelectedInstructor/@Rating" />
                              <xsl:text>)</xsl:text>
                              <br/>
                            </xsl:for-each>
                          </td>
                        </tr>
                      </xsl:for-each>
                    </table>
                    <br/>
                    <table>
                      <tr>
                        <td>
                          <xsl:variable name="VideoUrl" select="$Training/VideoUrl" />
                          <iframe width="420" height="315" src="{$VideoUrl}"></iframe>
                        </td>
                        <td class="description" width="420">
                          <p>
                            <b>Description:</b>
                          </p>
                          <p>
                            <xsl:value-of select="$Training/Description" />
                          </p>
                        </td>
                      </tr>
                    </table>
                  </li>
                </xsl:if>
              </xsl:for-each>
            </ul>
          </div>
          <br/>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

XSLT (xml)

<?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" cdata-section-elements="Name Style Comment"/>

  <xsl:template match="/">
    <Schedule>
      <xsl:for-each select="/Trainings/Training">
        <xsl:sort select="Name"/>
        <xsl:variable name="SelectedTraining" select="." />
        <xsl:for-each select="Schedule/ScheduleItem">
          <xsl:sort select="Time"/>
          <ScheduleItem>
            <xsl:variable name="VenueId" select="@VenueId" />
            <xsl:variable name="SelectedVenue" select="/Trainings/Venues/Venue[@Id=$VenueId]" />
            <xsl:attribute name="Id">
              <xsl:value-of select="@Id"/>
            </xsl:attribute>
            <xsl:attribute name="GroupSize">
              <xsl:choose>
                <xsl:when test="@GroupSize">
                  <xsl:value-of select="@GroupSize"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="$SelectedVenue/@GroupSize"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:attribute>
            <Venue>
              <xsl:attribute name="Id">
                <xsl:value-of select="$VenueId"/>
              </xsl:attribute>
              <xsl:value-of select="$SelectedVenue"/>
            </Venue>
            <Training>
              <xsl:attribute name="Id">
                <xsl:value-of select="$SelectedTraining/@Id"/>
              </xsl:attribute>
              <xsl:if test="$SelectedTraining/@Licence">
                <xsl:attribute name="Licence">
                  <xsl:value-of select="$SelectedTraining/@Licence"/>
                </xsl:attribute>
              </xsl:if>
              <Name>
                <xsl:value-of select="$SelectedTraining/Name"/>
              </Name>
              <Styles>
                <xsl:for-each select="$SelectedTraining/Styles/Style">
                  <xsl:variable name="StyleId" select="@Id" />
                  <Style>
                    <xsl:attribute name="StyleId">
                      <xsl:value-of select="$StyleId"/>
                    </xsl:attribute>
                    <xsl:value-of select="/Trainings/Styles/Style[@Id=$StyleId]"/>
                  </Style>
                </xsl:for-each>
              </Styles>
            </Training>
            <Time>
              <xsl:attribute name="Duration">
                <xsl:value-of select="Time/@Duration"/>
              </xsl:attribute>
              <xsl:value-of select ="Time"/>
            </Time>
            <Instructors>
              <xsl:for-each select="Instructors/Instructor">
                <xsl:variable name="InstructorId" select="@Id"/>
                <xsl:variable name="SelectedInstructor" select="/Trainings/Instructors/Instructor[@Id=$InstructorId]"/>
                <Instructor>
                  <xsl:attribute name="Id">
                    <xsl:value-of select="$InstructorId"/>
                  </xsl:attribute>
                  <xsl:attribute name="Rating">
                    <xsl:value-of select="$SelectedInstructor/@Rating"/>
                  </xsl:attribute>
                  <Name>
                    <xsl:value-of select="$SelectedInstructor/Name"/>
                  </Name>
                </Instructor>
              </xsl:for-each>
            </Instructors>
            <xsl:if test="Comment">
              <Comment>
                <xsl:value-of select="Comment"/>
              </Comment>
            </xsl:if>
          </ScheduleItem>
        </xsl:for-each>
      </xsl:for-each>
    </Schedule>
  </xsl:template>
</xsl:stylesheet>

XML (transformed)

<?xml version="1.0" encoding="utf-8"?>
<Schedule>
  <ScheduleItem Id="3" GroupSize="30">
    <Venue Id="2">Hall 2</Venue>
    <Training Id="2" Licence="LesMills">
      <Name><![CDATA[BodyBalance™]]></Name>
      <Styles>
        <Style StyleId="2"><![CDATA[Body&Mind]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT1H15M">2017-03-30T13:30:00</Time>
    <Instructors>
      <Instructor Id="3" Rating="4.6">
        <Name><![CDATA[Minnie Mouse]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="2" GroupSize="30">
    <Venue Id="3">Hall 3</Venue>
    <Training Id="2" Licence="LesMills">
      <Name><![CDATA[BodyBalance™]]></Name>
      <Styles>
        <Style StyleId="2"><![CDATA[Body&Mind]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT1H15M">2017-03-31T12:15:00</Time>
    <Instructors>
      <Instructor Id="2" Rating="4.7">
        <Name><![CDATA[Mickey Mouse]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="4" GroupSize="30">
    <Venue Id="3">Hall 3</Venue>
    <Training Id="3" Licence="LesMills">
      <Name><![CDATA[BodyJam™]]></Name>
      <Styles>
        <Style StyleId="4"><![CDATA[Dance&Fun]]></Style>
        <Style StyleId="1"><![CDATA[Cardio]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT60M">2017-03-30T16:10:00</Time>
    <Instructors>
      <Instructor Id="4" Rating="4.2">
        <Name><![CDATA[Donald Duck]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="5" GroupSize="20">
    <Venue Id="5">Hall 5</Venue>
    <Training Id="3" Licence="LesMills">
      <Name><![CDATA[BodyJam™]]></Name>
      <Styles>
        <Style StyleId="4"><![CDATA[Dance&Fun]]></Style>
        <Style StyleId="1"><![CDATA[Cardio]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT45M">2017-04-01T12:00:00</Time>
    <Instructors>
      <Instructor Id="5" Rating="3.9">
        <Name><![CDATA[Goofy]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="7" GroupSize="45">
    <Venue Id="1">Main Hall</Venue>
    <Training Id="4" Licence="LesMills">
      <Name><![CDATA[BodyPump™]]></Name>
      <Styles>
        <Style StyleId="3"><![CDATA[Strength]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT60M">2017-03-23T13:00:00</Time>
    <Instructors>
      <Instructor Id="6" Rating="5">
        <Name><![CDATA[Arnold Schwarzenegger]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="6" GroupSize="45">
    <Venue Id="1">Main Hall</Venue>
    <Training Id="4" Licence="LesMills">
      <Name><![CDATA[BodyPump™]]></Name>
      <Styles>
        <Style StyleId="3"><![CDATA[Strength]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT60M">2017-03-30T13:00:00</Time>
    <Instructors>
      <Instructor Id="6" Rating="5">
        <Name><![CDATA[Arnold Schwarzenegger]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="8" GroupSize="10">
    <Venue Id="6">Area 6</Venue>
    <Training Id="5">
      <Name><![CDATA[CoreStrength]]></Name>
      <Styles>
        <Style StyleId="3"><![CDATA[Strength]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT2H">2017-03-23T12:00:00</Time>
    <Instructors>
      <Instructor Id="9" Rating="5">
        <Name><![CDATA[Margaret Strengthener]]></Name>
      </Instructor>
    </Instructors>
    <Comment><![CDATA[
          Special challenge!
        ]]></Comment>
  </ScheduleItem>
  <ScheduleItem Id="9" GroupSize="15">
    <Venue Id="6">Area 6</Venue>
    <Training Id="5">
      <Name><![CDATA[CoreStrength]]></Name>
      <Styles>
        <Style StyleId="3"><![CDATA[Strength]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT60M">2017-03-30T12:00:00</Time>
    <Instructors>
      <Instructor Id="8" Rating="4.8">
        <Name><![CDATA[Kayla Weightlifter]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="10" GroupSize="15">
    <Venue Id="6">Area 6</Venue>
    <Training Id="5">
      <Name><![CDATA[CoreStrength]]></Name>
      <Styles>
        <Style StyleId="3"><![CDATA[Strength]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT60M">2017-04-05T12:00:00</Time>
    <Instructors>
      <Instructor Id="8" Rating="4.8">
        <Name><![CDATA[Kayla Weightlifter]]></Name>
      </Instructor>
      <Instructor Id="9" Rating="5">
        <Name><![CDATA[Margaret Strengthener]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="11" GroupSize="30">
    <Venue Id="2">Hall 2</Venue>
    <Training Id="6">
      <Name><![CDATA[Zumba®]]></Name>
      <Styles>
        <Style StyleId="4"><![CDATA[Dance&Fun]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT55M">2017-03-26T15:00:00</Time>
    <Instructors>
      <Instructor Id="7" Rating="4.2">
        <Name><![CDATA[Arnold Zumbaschnegger]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="12" GroupSize="20">
    <Venue Id="4">Hall 4</Venue>
    <Training Id="6">
      <Name><![CDATA[Zumba®]]></Name>
      <Styles>
        <Style StyleId="4"><![CDATA[Dance&Fun]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT60M">2017-03-28T12:00:00</Time>
    <Instructors>
      <Instructor Id="7" Rating="4.2">
        <Name><![CDATA[Arnold Zumbaschnegger]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="13" GroupSize="30">
    <Venue Id="2">Hall 2</Venue>
    <Training Id="6">
      <Name><![CDATA[Zumba®]]></Name>
      <Styles>
        <Style StyleId="4"><![CDATA[Dance&Fun]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT60M">2017-03-30T12:00:00</Time>
    <Instructors>
      <Instructor Id="7" Rating="4.2">
        <Name><![CDATA[Arnold Zumbaschnegger]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="1" GroupSize="30">
    <Venue Id="7">Yoga Hall</Venue>
    <Training Id="1">
      <Name><![CDATA[Yoga]]></Name>
      <Styles>
        <Style StyleId="2"><![CDATA[Body&Mind]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT60M">2017-03-25T14:00:00</Time>
    <Instructors>
      <Instructor Id="1" Rating="5">
        <Name><![CDATA[Minnie Yogafier]]></Name>
      </Instructor>
    </Instructors>
  </ScheduleItem>
  <ScheduleItem Id="14" GroupSize="15">
    <Venue Id="7">Yoga Hall</Venue>
    <Training Id="1">
      <Name><![CDATA[Yoga]]></Name>
      <Styles>
        <Style StyleId="2"><![CDATA[Body&Mind]]></Style>
      </Styles>
    </Training>
    <Time Duration="PT1H20M">2017-03-28T14:00:00</Time>
    <Instructors>
      <Instructor Id="1" Rating="5">
        <Name><![CDATA[Minnie Yogafier]]></Name>
      </Instructor>
    </Instructors>
    <Comment><![CDATA[
          Special class!
        ]]></Comment>
  </ScheduleItem>
</Schedule>

Log

  • 03.03.17 Esimene kohtumine. Idee.
  • 17.03.17 Osa XMList valmis, osa XSLT-st valmis
  • 18.03.17 Teine kohtumine. XMLi täiendamine, esimene ülekäimine XSD-s.
  • 19.03.17 XML/XSLT/XSD täiendamine ja lõpetamine.