Ott

From ICO wiki
Revision as of 14:11, 27 March 2017 by Osoeruma (talk | contribs) (Created page with "=Kodutöö aines "Võrgurakendused II: hajussüsteemide ehitamine"= ==Meeskond== *Ott Sõerumäe =XML/XSD/XSLT= === XML === <source lang="xml"> <?xml version="1.0" encoding...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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

Meeskond

  • Ott Sõerumäe

XML/XSD/XSLT

XML

<?xml version="1.0" encoding="utf-8" ?>
<!--See XML andmefail hoiab andmeid erinevate klassikalise muusika teoste kohta,-->
<!--et nt muusikakooli õpilastel oleks lihtsam endale meeldivat ja enda tasemele vastava raskusastmega teost mängimiseks valida-->
<composers>
  <composer born="1687" died="1750">
    <name><![CDATA[Johann Sebastian Bach]]></name>
    <description><![CDATA[Bach has widely been considered the greatest composer of all time.]]></description>
    <era><![CDATA[Baroque]]></era>
    <pieces>
      <piece type="Partita" no="2" instrument="violin" published="1720" grade="10">
        <tempo><![CDATA[Tempo di ciaccona]]></tempo>
        <key><![CDATA[D Minor]]></key>
        <title><![CDATA[Chaconne]]></title>
      </piece>
    </pieces>
  </composer>
  <composer born="1810" died="1849">
    <name><![CDATA[Frederic Chopin]]></name>
    <description><![CDATA[He was one of the greatest pianists of the Romantic era.]]></description>
    <era><![CDATA[Early Romantic]]></era>
    <pieces>
      <piece type="Etude" op="10" no="1" instrument="piano" published="1832" grade="10">
        <tempo bpm="176"><![CDATA[Allegro]]></tempo>
        <key><![CDATA[C Major]]></key>
        <title><![CDATA[Waterfall]]></title>
      </piece>
      <piece type="Etude" op="10" no="2" instrument="piano" published="1832" grade="10">
        <tempo bpm="144"><![CDATA[Allegro]]></tempo>
        <key><![CDATA[A Minor]]></key>
        <title><![CDATA[Chromatic]]></title>
      </piece>
      <piece type="Etude" op="10" no="3" instrument="piano" published="1832" grade="7">
        <tempo bpm="100"><![CDATA[Lento ma non troppo]]></tempo>
        <key><![CDATA[E Major]]></key>
        <title><![CDATA[Tristesse]]></title>
      </piece>
      <piece type="Etude" op="10" no="4" instrument="piano" published="1832" grade="10">
        <tempo bpm="176"><![CDATA[Presto]]></tempo>
        <key><![CDATA[C# Minor]]></key>
        <title><![CDATA[Torrent]]></title>
      </piece>
      <piece type="Etude" op="25" no="12" instrument="piano" published="1836" grade="10">
        <tempo bpm="160"><![CDATA[Allegro molto con fuoco]]></tempo>
        <key><![CDATA[C Minor]]></key>
        <title><![CDATA[Ocean]]></title>
      </piece>
      <piece type="Prelude" op="28" no="15" instrument="piano" published="1834" grade="4">
        <tempo><![CDATA[Sostenuto]]></tempo>
        <key><![CDATA[D-Flat Major]]></key>
        <title><![CDATA[Raindrop]]></title>
      </piece>
      <piece type="Prelude" op="28" no="20" instrument="piano" published="1834" grade="5">
        <tempo><![CDATA[Largo]]></tempo>
        <key><![CDATA[C Minor]]></key>
      </piece>
      <piece type="Ballade" op="23" no="1" instrument="piano" published="1835" grade="10">
        <tempo><![CDATA[Largo]]></tempo>
        <key><![CDATA[G Minor]]></key>
      </piece>
      <piece type="Ballade" op="52" no="4" instrument="piano" published="1842" grade="10">
        <tempo><![CDATA[Andante con moto]]></tempo>
        <key><![CDATA[F Minor]]></key>
      </piece>
    </pieces>
  </composer>
  <composer born="1782" died="1840">
    <name><![CDATA[Niccolo Paganini]]></name>
    <description><![CDATA[Paganini is the greatest violinist of all times:]]></description>
    <era><![CDATA[Early Romantic]]></era>
    <pieces>
      <piece type="Caprice" op="1" no="1" instrument="violin" published="1802" grade="10">
        <tempo><![CDATA[Andante]]></tempo>
        <key><![CDATA[E Major]]></key>
        <title><![CDATA[Arpeggios]]></title>
      </piece>
      <piece type="Caprice" op="1" no="2" instrument="violin" published="1802" grade="10">
        <tempo><![CDATA[Moderato]]></tempo>
        <key><![CDATA[B Minor]]></key>
      </piece>
      <piece type="Caprice" op="1" no="3" instrument="violin" published="1802" grade="10">
        <tempo><![CDATA[Sostenuto]]></tempo>
        <key><![CDATA[E Minor]]></key>
        <title><![CDATA[Octaves]]></title>
      </piece>
      <piece type="Caprice" op="1" no="4" instrument="violin" published="1802" grade="10">
        <tempo><![CDATA[Maestoso]]></tempo>
        <key><![CDATA[C Minor]]></key>
        <title><![CDATA[Thirds]]></title>
      </piece>
      <piece type="Caprice" op="1" no="5" instrument="violin" published="1802" grade="10">
        <tempo><![CDATA[Agitato]]></tempo>
        <key><![CDATA[A Minor]]></key>
      </piece>
      <piece type="Caprice" op="1" no="24" instrument="violin" published="1817" grade="10">
        <tempo><![CDATA[Quasi presto]]></tempo>
        <key><![CDATA[A Minor]]></key>
      </piece>
    </pieces>
  </composer>
  <composer born="1873" died="1943">
    <name><![CDATA[Sergei Rachmaninoff]]></name>
    <description><![CDATA[Sergei Rachmaninoff is undoubtedly my favourite composer :D]]></description>
    <era><![CDATA[Late Romantic]]></era>
    <pieces>
      <piece type="Prelude" op="3" no="2" instrument="piano" published="1892" grade="9">
        <tempo><![CDATA[Lento]]></tempo>
        <key><![CDATA[C# Minor]]></key>
      </piece>
      <piece type="Prelude" op="23" no="1" instrument="piano" published="1901" grade="9">
        <tempo><![CDATA[Largo]]></tempo>
        <key><![CDATA[F# Minor]]></key>
      </piece>
      <piece type="Prelude" op="23" no="2" instrument="piano" published="1901" grade="9">
        <tempo><![CDATA[Maestoso]]></tempo>
        <key><![CDATA[B-flat Major]]></key>
      </piece>
      <piece type="Prelude" op="23" no="3" instrument="piano" published="1903" grade="9">
        <tempo><![CDATA[Tempo di minuetto]]></tempo>
        <key><![CDATA[D Minor]]></key>
      </piece>
      <piece type="Prelude" op="23" no="4" instrument="piano" published="1902" grade="9">
        <tempo><![CDATA[Andante cantabile]]></tempo>
        <key><![CDATA[D Major]]></key>
      </piece>
      <piece type="Prelude" op="23" no="5" instrument="piano" published="1901" grade="10">
        <tempo><![CDATA[Alla marcia]]></tempo>
        <key><![CDATA[G Minor]]></key>
      </piece>
      <piece type="Prelude" op="32" no="10" instrument="piano" published="1910" grade="8">
        <tempo><![CDATA[Lento]]></tempo>
        <key><![CDATA[B minor]]></key>
      </piece>
      <piece type="Etude" op="39" no="6" instrument="piano" published="1917" grade="10">
        <tempo><![CDATA[Allegro]]></tempo>
        <key><![CDATA[A minor]]></key>
        <title><![CDATA[Little Red Riding Hood]]></title>
      </piece>
    </pieces>
  </composer> 
</composers>

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="composers">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="composer">
          <xs:complexType>
            <xs:sequence> <!--Järjekord omab tähtsust-->
              <xs:element name="name" type="xs:string" />
              <xs:element name="description" type="xs:string" />
              <xs:element name="era" type="xs:string" />
              <xs:element name="pieces">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="piece">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="tempo" minOccurs="0" maxOccurs="1">
                            <xs:complexType>
                              <xs:simpleContent>
                                <xs:extension base="xs:string">
                                  <xs:attribute name="bpm" type="xs:integer" use="optional" />
                                </xs:extension>
                              </xs:simpleContent>
                            </xs:complexType>
                          </xs:element>
                          <xs:element name="key" minOccurs="0" maxOccurs="1" type="xs:string" />
                          <xs:element name="title" minOccurs="0" maxOccurs="1" type="xs:string" />
                        </xs:sequence>
                        <xs:attribute name="type" type="xs:string" use="required" />
                        <xs:attribute name="op" type="xs:integer" use="optional" />
                        <xs:attribute name="no" type="xs:integer" use="optional" />
                        <xs:attribute name="instrument" type="xs:string" use="required" />
                        <xs:attribute name="published" type="xs:unsignedShort" use="required" />
                        <xs:attribute name="grade" type="xs:unsignedByte" use="required" />
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="born" type="xs:unsignedShort" use="required" />
            <xs:attribute name="died" type="xs:unsignedShort" use="optional" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

XSLT

XSLT HTML (Heliloojate ja nende teoste HTML vormingus kuvamine:)

<?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>
        <body>
          <h1>Composers:</h1>
          <xsl:for-each select="composers/composer">
            <h3>
              <xsl:value-of select="name"/>
              <xsl:choose>
                <xsl:when test="@died">
                  (<xsl:value-of select="@born"/> - <xsl:value-of select="@died"/>)
                </xsl:when>
                <xsl:otherwise>
                  (Born in <xsl:value-of select="@born"/>)
                </xsl:otherwise>
              </xsl:choose>
            </h3>
            <p>
              <xsl:value-of select="description"/>
            </p>
            <h4>Pieces:</h4>
            <table border="1">
              <tr bgcolor="ffbc55">
                <td>Title:</td>
                <td>Key:</td>
                <td>Published:</td>
                <td>Grade:</td>
              </tr>
              <xsl:for-each select="pieces/piece">
                <tr>
                  <td>
                    <xsl:value-of select="@type"/>&#160;
                    <xsl:if test="@op">
                      Op.
                      <xsl:value-of select="@op"/>&#160;
                    </xsl:if>
                    <xsl:if test="@no">
                      No.
                      <xsl:value-of select="@no"/>&#160;
                    </xsl:if>
                    <xsl:value-of select="tempo"/>&#160;
                    <xsl:if test="title">
                      "<xsl:value-of select="title"/>"
                    </xsl:if>
                  </td>
                  <td>
                    <xsl:value-of select="key"/>
                  </td>
                  <td>
                    <xsl:value-of select="@published"/>
                  </td>
                  <td>
                    <xsl:value-of select="@grade"/>
                  </td>
                </tr>
              </xsl:for-each>
            </table>
          </xsl:for-each>
        </body>
      </html>
    </xsl:template>
</xsl:stylesheet>

XSLT XML: XML-i struktuuri muutmine

<?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="/">
    <pieces>
      <xsl:for-each select="/composers/composer/pieces/piece">
        <piece>
          <xsl:attribute name="tempo">
            <xsl:value-of select="tempo"/>
          </xsl:attribute>
          <xsl:attribute name="bpm">
            <xsl:value-of select="tempo/@bpm"/>
          </xsl:attribute>
          <longTitle>
            <xsl:value-of select="concat(@type, ' Op. ', @op, ' No. ', @no, ' ', title)"/>
          </longTitle>
          <difficultyLevel>
            <xsl:value-of select="@grade"/>
          </difficultyLevel>
          <instrument>
            <xsl:value-of select="@instrument"/>
          </instrument>
        </piece>
      </xsl:for-each>
    </pieces>
  </xsl:template>
</xsl:stylesheet>