Kurad1t051n: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Line 313: Line 313:
=== XSLT failid ===
=== XSLT failid ===


==== XML -> HTML ====
Creates a html printout containing movie title, year and rating...
Creates a html printout containing movie title, year and rating...


Line 358: Line 359:


</source>
</source>
==== XML -> XML ====


We only care of the times ahead and we want an updated xml so we deletes movies from the year 2010...
We only care of the times ahead and we want an updated xml so we deletes movies from the year 2010...

Revision as of 17:46, 16 April 2013

Meeskond

  • Liikmed:
    • Tanel Milsaar

Idee

Filmid...


Ülesanne 1 - XML

Tähtaeg 15.04.2013

XML fail

<?xml version="1.0" encoding="utf-8"?>
<movies>
  <movie>
    <name>Iron Man 2</name>
    <year>2010</year>
    <uri>http://www.imdb.com/title/tt1228705/</uri>
    <release>
      <status>
        <code>RELEASED</code>
        <name>Released</name>
      </status>
      <date>2010-04-30</date>
    </release>
    <rating>
      <value>7.1</value>
      <uri>http://www.imdb.com/title/tt1228705/</uri>
    </rating>
    <genres>
      <genre>
        <code>ACTION</code>
        <name>Action</name>
        <uri>http://www.imdb.com/genre/action/</uri>
      </genre>
	  <genre>
        <code>ADVENTURE</code>
        <name>Adventure</name>
        <uri>http://www.imdb.com/genre/adventure/</uri>
      </genre>
	  <genre>
        <code>SCIFI</code>
        <name>Sci-Fi</name>
        <uri>http://www.imdb.com/genre/sci_fi/</uri>
      </genre>
    </genres>
    <description>Tony Stark has declared himself Iron Man and installed world peace... or so he thinks. He soon realizes that not only is there a mad man out to kill him with his own technology, but there's something more: he is dying.</description>
    <directors>
      <director>
        <name>Jon Favreau</name>
        <uri>http://www.imdb.com/name/nm0269463/</uri>
      </director>
    </directors>
    <writers>
      <writer>
        <name>Justin Theroux</name>
        <uri>http://www.imdb.com/name/nm0857620/</uri>
        <type>
          <code>SCREENPLAY</code>
          <name>screenplay</name>
        </type>
      </writer>
	  <writer>
        <name>Stan Lee</name>
        <uri>http://www.imdb.com/name/nm0498278/</uri>
        <type>
          <code>MARVEL_COMIC</code>
          <name>Marvel comic book</name>
        </type>
      </writer>
    </writers>
    <stars>
      <star>
        <name>Robert Downey Jr.</name>
        <uri>http://www.imdb.com/name/nm0000375/</uri>
      </star>
      <star>
        <name>Gwyneth Paltrow</name>
        <uri>http://www.imdb.com/name/nm0000569/</uri>
      </star>
      <star>
        <name>Don Cheadle</name>
        <uri>http://www.imdb.com/name/nm0000332/</uri>
      </star>
    </stars>
    <cast>
      <character>
        <name>Natalie Rushman</name>
	<name>Natasha Romanoff</name>
        <actor>
          <name>Scarlett Johansson</name>
          <uri>http://www.imdb.com/name/nm0424060/</uri>
        </actor>
	<uri>http://www.imdb.com/character/ch0183355/</uri>
      </character>
      <uri>http://www.imdb.com/title/tt1228705/fullcredits/</uri>
    </cast>
  </movie>
    <movie>
    <name>Sin City: A Dame to Kill For</name>
    <year>2013</year>
    <uri>http://www.imdb.com/title/tt0458481/</uri>
    <release>
      <status>
        <code>NOT_YET_RELEASED</code>
        <name>Not yet released</name>
      </status>
      <date>2013-10-04</date>
    </release>
    <rating/>
    <genres>
      <genre>
        <code>ACTION</code>
        <name>Action</name>
        <uri>http://www.imdb.com/genre/action/</uri>
      </genre>
	  <genre>
        <code>CRIME</code>
        <name>Crime</name>
        <uri>http://www.imdb.com/genre/Crime/</uri>
      </genre>
	  <genre>
        <code>THRILLER</code>
        <name>Thriller</name>
        <uri>http://www.imdb.com/genre/Thriller/</uri>
      </genre>
    </genres>
    <description>The town's most hard boiled citizens cross paths with some of its more reviled inhabitants.</description>
    <directors>
      <director>
        <name>Frank Miller</name>
        <uri>http://www.imdb.com/name/nm0588340/</uri>
      </director>
	  <director>
        <name>Robert Rodriguez</name>
        <uri>http://www.imdb.com/name/nm0001675/</uri>
      </director>
    </directors>
    <writers>
      <writer>
        <name>Frank Miller</name>
        <uri>http://www.imdb.com/name/nm0588340/</uri>
        <type>
          <code>GRAPHIC_NOVELS</code>
          <name>graphic novels</name>
        </type>
      </writer>
	  <writer>
        <name>Frank Miller</name>
        <uri>http://www.imdb.com/name/nm0588340/</uri>
        <type>
          <code>SCREENPLAY</code>
          <name>screenplay</name>
        </type>
      </writer>
    </writers>
    <stars>
      <star>
        <name>Robert Downey Jr.</name>
        <uri>http://www.imdb.com/name/nm0330687/</uri>
      </star>
      <star>
        <name>Rosario Dawson</name>
        <uri>http://www.imdb.com/name/nm0206257/</uri>
      </star>
      <star>
        <name>Jessica Alba</name>
        <uri>http://www.imdb.com/name/nm0004695/</uri>
      </star>
    </stars>
    <cast>
      <character>
        <name>John Hartigan</name>
        <actor>
          <name>Bruce Willis</name>
          <uri>http://www.imdb.com/name/nm0000246/</uri>
        </actor>
		<uri>http://www.imdb.com/character/ch0002538/</uri>
	  </character>
	  <uri>http://www.imdb.com/title/tt0458481/fullcredits/</uri>
    </cast>
  </movie>
</movies>

XSD fail

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.example.org/movies"
           elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:tns="http://www.example.org/movies">

  <xs:element name="movies" type="tns:movies"></xs:element>

  <xs:complexType name="movies">
    <xs:sequence>
      <xs:element name="movie" type="tns:movie" maxOccurs="unbounded" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="movie">
    <xs:sequence>
      <xs:element name="name" type="xs:string" maxOccurs="1" minOccurs="1"></xs:element>
      <xs:element name="year" type="xs:gYear" maxOccurs="1" minOccurs="1"></xs:element>
      <xs:element name="uri" type="xs:anyURI" maxOccurs="1" minOccurs="0"></xs:element>
      <xs:element name="release" type="tns:release" maxOccurs="1" minOccurs="0"></xs:element>
      <xs:element name="rating" type="tns:rating" maxOccurs="1" minOccurs="0"></xs:element>
      <xs:element name="genres" type="tns:genres" maxOccurs="1" minOccurs="1"></xs:element>
      <xs:element name="description" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
      <xs:element name="directors" type="tns:directors" maxOccurs="1" minOccurs="0"></xs:element>
      <xs:element name="writers" type="tns:writers" maxOccurs="1" minOccurs="0"></xs:element>
      <xs:element name="stars" type="tns:stars" maxOccurs="1" minOccurs="0"></xs:element>
      <xs:element name="cast" type="tns:character" maxOccurs="1" minOccurs="0"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="release">
    <xs:sequence>
      <xs:element name="status" type="tns:baseType" maxOccurs="1" minOccurs="1"></xs:element>
      <xs:element name="date" type="xs:date" maxOccurs="1" minOccurs="0"></xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="rating">
    <xs:sequence>
      <xs:element name="value" type="xs:double" maxOccurs="1" minOccurs="1"></xs:element>
      <xs:element name="uri" type="xs:anyURI" maxOccurs="1" minOccurs="0"></xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="genres">
    <xs:sequence>
      <xs:element name="genre" type="tns:uriBaseType" maxOccurs="unbounded" minOccurs="1"></xs:element>
      <xs:element name="uri" type="xs:anyURI" maxOccurs="1" minOccurs="0"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="person">
    <xs:sequence>
      <xs:element name="name" type="xs:string" maxOccurs="1" minOccurs="1"></xs:element>
      <xs:element name="uri" type="xs:anyURI" maxOccurs="1" minOccurs="1"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="directors">
    <xs:sequence>
      <xs:element name="director" type="tns:person" maxOccurs="unbounded" minOccurs="1"></xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="writers">
    <xs:sequence>
      <xs:element name="writer" type="tns:writer" maxOccurs="unbounded" minOccurs="1"></xs:element>
      <xs:element name="uri" type="xs:anyURI" maxOccurs="1" minOccurs="0"></xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="writer">
    <xs:complexContent>
      <xs:extension base="tns:person">
        <xs:sequence>
          <xs:element name="type" type="tns:baseType" maxOccurs="1" minOccurs="0"></xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <xs:complexType name="stars">
    <xs:sequence>
      <xs:element name="star" type="tns:person" maxOccurs="unbounded" minOccurs="1"></xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="cast">
    <xs:sequence>
      <xs:element name="character" type="tns:character" maxOccurs="unbounded" minOccurs="1"></xs:element>
      <xs:element name="uri" type="xs:anyURI" maxOccurs="1" minOccurs="0"></xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="character">
    <xs:sequence>
      <xs:element name="name" type="xs:string" maxOccurs="unbounded" minOccurs="1"></xs:element>
      <xs:element name="actor" type="tns:person" maxOccurs="1" minOccurs="0"></xs:element>
      <xs:element name="uri" type="xs:anyURI" maxOccurs="1" minOccurs="0"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="baseType">
    <xs:sequence>
      <xs:element name="code" type="xs:string" maxOccurs="1" minOccurs="1"></xs:element>
      <xs:element name="name" type="xs:string" maxOccurs="1" minOccurs="1"></xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="uriBaseType">
    <xs:complexContent>
      <xs:extension base="tns:baseType">
        <xs:sequence>
          <xs:element name="uri" type="xs:anyURI" maxOccurs="1" minOccurs="0"></xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

</xs:schema>

XSLT failid

XML -> HTML

Creates a html printout containing movie title, year and rating...

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/movies">
  <html>
  <body>
  <h2>Some random movies</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Name</th>
        <th>Year</th>
        <th>ImDB rating</th>
      </tr>
      <xsl:for-each select="movie">
      <tr>
        <td>
          <xsl:variable name="uri" select="uri"/>
          <a href="{$uri}">
            <xsl:value-of select="name"/>
          </a>
        </td>
        <td><xsl:value-of select="year"/></td>
        <td>
          <xsl:choose>
            <xsl:when test="rating/value">
              <xsl:value-of select="rating/value"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="release/status/name"/>
            </xsl:otherwise>
          </xsl:choose>
        </td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

XML -> XML

We only care of the times ahead and we want an updated xml so we deletes movies from the year 2010...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="movies/movie[year = 2010]">

    </xsl:template>
</xsl:stylesheet>

Ülesanne 2 - Veebiteenus

Tähtaeg 20.05.2013

Ülesanne 3 - Klient

Tähtaeg 10.06.2013

Retsensioonid

XML