Meeskond "Kipsplaat"

From EIK wiki

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

Meeskonna liikmed

  • Daniil Slobodin
  • Oliver Vahenõmm
  • Kaspar Jesse Tormis
  • Alari Talvar

XML/XSD/2XSLT

XML

<?xml version="1.0" encoding="utf-8" ?>

<Shop>
  <Info>
    <Name>Kipsplaadi veebipood</Name>
    <Description>
      <![CDATA[Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
      Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
      Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
      Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.]]>
    </Description>
    <Contacts>
      <Contact type="Aadress">Raja 4C, Tallinn</Contact>
      <Contact type="E-mail">info@veebipood.ee</Contact>
      <Contact type="Telefon">+37258555555</Contact>
    </Contacts>
  </Info>

  <Categories>
    <Category>Arvutid</Category>
    <Category>Sülearvutid</Category>
    <Category>Mobiiltelefonid</Category>
  </Categories>

  <Products>
    <Product id="1" amount="3" category="Mobiiltelefonid">
      <Name>Apple iPhone 5s, Gold 16GB</Name>
      <Manufacturer>Apple</Manufacturer>
      <Images>
        <Image>Images/iPhone_5s_Gold.JPG</Image>
      </Images>
      <Code>B00F3J4E5U</Code>
      <Price unit="EUR">650</Price>
      <Description>
        <![CDATA[
        A chip with 64-bit architecture. 
        A fingerprint identity sensor. 
        A better, faster camera. 
        And an operating system built specifically for 64-bit. 
        Any one of these features in a smartphone would make it ahead of its time. 
        All of these features in a smartphone make it an iPhone that's definitely ahead of its time.
        ]]>
      </Description>
      <Data>
        <Type name="Size">16 GB</Type>
        <Type name="Color">Gold</Type>
        <Type name="Display">4.0-inch Retina</Type>
        <Type name="CPU">A7 chip with M7 motion coprocessor</Type>
        <Type name="Camera">8MP iSight camera with True Tone flash and 1080p HD video recording</Type>
        <Type name="Dimensions">2.3x0.3x4.9 inches</Type>
        <Type name="Weight">9.6 ounces</Type>
        <Type name="Other">Touch ID fingerprint sensor</Type>
      </Data>
    </Product>

    <Product id="2" amount="0" category="Sülearvutid">
      <Name>Dell Inspiron 15.6-Inch Laptop</Name>
      <Manufacturer>Dell</Manufacturer>
      <Images>
        <Image>Images/Dell.JPG</Image>
        <Image>Images/Dell2.JPG</Image>
      </Images>
      <Code>i15RV-954BLK</Code>
      <Price unit="EUR">255</Price>
      <Description>
        <![CDATA[
        Manage daily tasks with the affordable Inspiron 15 — a 15.6" laptop with the latest Intel Pentium processors, a thin design and 10-key number pad.
        ]]>
      </Description>
      <Data>
        <Type name="CPU">1.9 GHz Pentium 2127U</Type>
        <Type name="RAM">4 GB DDR3L SDRAM</Type>
        <Type name="HDD">500 GB</Type>
        <Type name="Screen">15.6 Inches 1366x768 pixels</Type>
        <Type name="OS">Windows 8</Type>
      </Data>
    </Product>
  </Products>

</Shop>

XML skeemifail

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Shop">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Info">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Name" type="xs:string" />
              <xs:element name="Description" type="xs:string" />
              <xs:element name="Contacts">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="20" 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:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="Categories">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="100" name="Category" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="Products">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="unbounded" name="Product">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="Name" type="xs:string" />
                    <xs:element name="Manufacturer" type="xs:string" />
                    <xs:element name="Images">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element maxOccurs="5" name="Image" type="xs:string" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <xs:element name="Code" type="xs:string" />
                    <xs:element name="Price">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:unsignedInt">
                            <xs:attribute name="unit" type="xs:string" use="required" />
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                    <xs:element name="Description" type="xs:string" />
                    <xs:element name="Data">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element maxOccurs="100" name="Type">
                            <xs:complexType>
                              <xs:simpleContent>
                                <xs:extension base="xs:string">
                                  <xs:attribute name="name" type="xs:string" use="required" />
                                </xs:extension>
                              </xs:simpleContent>
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="id" type="xs:unsignedInt" use="required" />
                  <xs:attribute name="amount" type="xs:unsignedInt" use="required" />
                  <xs:attribute name="category" type="xs:string" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

XSLT 1

Output: Tooted.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" indent="yes"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>
          <xsl:value-of select="Shop/Info/Name"/>
        </title>
        <style>
          #lisaOstukorvi {
          padding: 10px;
          width: 150px;
          background-color: #008000;
          border-radius:5px;
          color: white;
          text-style: bold;
          text-align: center;
          cursor: pointer;
          }
          #lisaOstukorvi:hover {
          background-color: #32CD32;
          }
          #toode {
          margin: 10px;
          padding: 10px;
          width: 750px;
          border: 2px solid black;
          border-radius: 2px;
          }
        </style>
      </head>
      <body>
        <xsl:for-each select="Shop/Products/Product">
          <xsl:sort select="@id"/>

          <!--Toode kirjeldus-->
          <div id="toode">
            <h2>
              <xsl:value-of select="Name"/>
            </h2>
            <em style="color: gray">
              ID: <xsl:value-of select="@id"/>
              Tootekood: <xsl:value-of select="Code"/>
            </em>
            <p>
              <xsl:value-of select="Description"/>
            </p>

            <!--Pildid-->
            <xsl:for-each select="Images/Image">
              <img height="250px">
                <xsl:attribute name="src">
                  <xsl:value-of select="."/>
                </xsl:attribute>
              </img>
            </xsl:for-each>

            <!--Spefikatsioonid-->
            <table>
              <xsl:for-each select="Data/Type">
                <tr>
                  <td>
                    <b>
                      <xsl:value-of select="@name"/>
                    </b>
                  </td>
                  <td>
                    <xsl:value-of select="."/>
                  </td>
                </tr>
              </xsl:for-each>
            </table>

            <!--Ostmine-->
            <p>
              <xsl:choose>
                <xsl:when test="@amount>'0'">
                  Kohal: <xsl:value-of select="@amount"/>
                </xsl:when>
                <xsl:otherwise>Ei ole antud hetkel saadaval. Vabandame!</xsl:otherwise>
              </xsl:choose>
            </p>
            <p>
              Hind: <xsl:value-of select="Price"/> <xsl:value-of select="Price/@unit"/>
            </p>
            <div id="lisaOstukorvi">
              Lisa ostukorvi
            </div>
          </div>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

XSLT 2

Output: About.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" indent="yes"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>About</title>
        <style>
          div {
          width: 750px;
          margin: 10px;
          padding: 10px;
          border: 2px solid black;
          border-radius: 2px;
          }
        </style>
      </head>
      <body>
        <header>
          <h1>
            <xsl:value-of select="Shop/Info/Name"/>
          </h1>
        </header>
        <div>
          <h2>Kes me oleme?</h2>
          <p>
            <xsl:value-of select="Shop/Info/Description"/>
          </p>

          <h2>Meil on müügis:</h2>
          <xsl:for-each select="Shop/Categories/Category">
            <ul>
              <li>
                <xsl:value-of select="."/>
              </li>
            </ul>
          </xsl:for-each>

          <!--Kontaktandmed-->
          <h2>Kontaktandmed:</h2>
          <table>
            <xsl:for-each select="Shop/Info/Contacts/Contact">
              <tr>
                <td style="font-weight: bold;">
                  <xsl:value-of select="@type"/>
                </td>
                <td style="color: gray;">
                  <xsl:value-of select="."/>
                </td>
              </tr>
            </xsl:for-each>
          </table>

          <!--Kaart-->
          <h2>Meie asukoht kaardil:</h2>
          <img style="display: block; border: 1px solid black;">
            <xsl:variable name="Aadress" select="/Shop/Info/Contacts/Contact[@type='Aadress']"/>
            <xsl:attribute name="src">
              http://maps.googleapis.com/maps/api/staticmap?center=<xsl:value-of select="$Aadress"/>&zoom=15&size=400x400&markers=color:blue%7Clabel:A%7C<xsl:value-of select="$Aadress"/>&maptype=roadmap&sensor=false
            </xsl:attribute>
          </img>

        </div>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

Kipsplaadi logi

  • 15.03.2014 Kaks XML retsensiooni on valmis
  • 8.03.2014 XML andmefail/XSD skeemifail ja 2 XSLT faili on valmis
  • 8.03.2014 Wiki lehe loomine