Meeskond:VariableMoods2

From ICO wiki
Revision as of 18:23, 5 March 2015 by Mkunnapa (talk | contribs)
Jump to navigationJump to search

Liikmed

  • Mihkel Künnapas
  • Krister Kamla - projektijuht
  • Berit Veidemann

XML

Veebipoe tootekataloog

<?xml version="1.0" encoding="utf-8" ?>
<Catalog currency="eur">
  <Category id="1" visible="true">
    <Name><![CDATA[Riided]]></Name>
    <Description><![CDATA[Asjad, mida saab selga panna]]></Description>
    <Image><![CDATA[riided.JPG]]></Image>
    <SubCategory id="2" visible="true">
      <Name><![CDATA[Sokid]]></Name>
      <Description><![CDATA[Vähemalt paari kaupa müügil olev energiasõltumatu jalasoojendusvahend]]></Description>
      <Image><![CDATA[sokid.JPG]]></Image>
      <Product id="1" serialCode="AB4756478sd" priority="1" visible="true">
        <Name><![CDATA[Selvä sokki]]></Name>
        <Description><![CDATA[Väga head soojad sokid meestele]]></Description>
        <Image><![CDATA[selva.JPG]]></Image>  
        <Price>2.00</Price>
        <DiscountPrice >1.80</DiscountPrice>
        <Size unit=""><![CDATA[M-XXL]]></Size>
        <Quantity unit="tk">40</Quantity>
        <Guarantee unit="aastat">3</Guarantee>
        <Tags>
          <Tag id="1"><![CDATA[Meestele]]></Tag>
        </Tags>
      </Product>
      <Product id="2" serialCode="AB4756478se" priority="1" visible="true">
        <Name><![CDATA[Hüva sokki]]></Name>
        <Description><![CDATA[Väga head soojad sokid naistele, roosa]]></Description>
        <Image><![CDATA[hyvaSokk.JPG]]></Image>
        <Price>1.40</Price>
        <DiscountPrice>0</DiscountPrice>
        <Size unit=""><![CDATA[S-L]]></Size>
        <Quantity unit="tk">12</Quantity>
        <Guarantee unit="aastat">3</Guarantee>
        <Tags>
          <Tag id="2"><![CDATA[70-ndad]]></Tag>
          <Tag id="3"><![CDATA[Naistele]]></Tag>
          <Tag id="4"><![CDATA[Kingitused]]></Tag>
        </Tags>
      </Product>
    </SubCategory>
  </Category>
  <Category id="3" visible="true">
    <Name><![CDATA[Toidukaubad]]></Name>
    <Description><![CDATA[Asjad, mida saab suhu panna]]></Description>
    <Image><![CDATA[toidud.JPG]]></Image>
    <SubCategory id="4" visible="true">
      <Name><![CDATA[Maiustused]]></Name>
      <Description><![CDATA[Hammastele kahjulikud kaubad]]></Description>
      <Image><![CDATA[komm.JPG]]></Image>
      <Product id="3" serialCode="Aa756478sd" priority="2" visible="true">
        <Name><![CDATA[Selga küpsised]]></Name>
        <Description><![CDATA[MMM selga]]></Description>
        <Image><![CDATA[selga.JPG]]></Image>
        <Price>0.64</Price>
        <DiscountPrice>0.62</DiscountPrice>
        <Size unit="g"><![CDATA[400]]></Size>
        <Quantity unit="tk">600</Quantity>
        <Guarantee unit="">0</Guarantee>
        <Tags>
          <Tag id="3"><![CDATA[Naistele]]></Tag>
        </Tags>
      </Product>
      <Product id="4" serialCode="Ax4776478se" priority="1" visible="false">
        <Name><![CDATA[Martsipan]]></Name>
        <Description><![CDATA[MMM martsipan]]></Description>
        <Image><![CDATA[martsipan.JPG]]></Image>
        <Price>2.60</Price>
        <DiscountPrice>0</DiscountPrice>
        <Size unit="g"><![CDATA[170]]></Size>
        <Quantity unit="tk">37</Quantity>
        <Guarantee unit="">0</Guarantee>
        <Tags>
          <Tag id="5"><![CDATA[Ostjate lemmik]]></Tag>
          <Tag id="6"><![CDATA[Nädala diil]]></Tag>
        </Tags>
      </Product>
    </SubCategory>
    <SubCategory id="5" visible="false">
      <Name><![CDATA[Hommikueined]]></Name>
      <Description><![CDATA[Hommikusöök on kõige tähtsam!]]></Description>
      <Image><![CDATA[puder.JPG]]></Image>
      <Product id="5" serialCode="Ax4776asdf8se" priority="1" visible="true">
        <Name><![CDATA[Neljaviljapuder]]></Name>
        <Description><![CDATA[Väkk puder]]></Description>
        <Image><![CDATA[4puder.JPG]]></Image>
        <Price>1.00</Price>
        <DiscountPrice>0</DiscountPrice>
        <Size unit="g"><![CDATA[500]]></Size>
        <Quantity unit="tk">8</Quantity>
        <Guarantee unit="">0</Guarantee>
        <Tags>
          <Tag id="7"><![CDATA[Keegi ei osta]]></Tag>
          <Tag id="8"><![CDATA[Parim enne möödunud]]></Tag>
        </Tags>
      </Product>
    </SubCategory>
  </Category>
</Catalog>

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="Catalog">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="Category">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Name" type="xs:string" />
              <xs:element name="Description" type="xs:string" />
              <xs:element name="Image" type="xs:string" />
              <xs:element maxOccurs="unbounded" name="SubCategory">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="Name" type="xs:string" />
                    <xs:element name="Description" type="xs:string" />
                    <xs:element name="Image" type="xs:string" />
                    <xs:element maxOccurs="unbounded" name="Product">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="Name" type="xs:string" />
                          <xs:element name="Description" type="xs:string" />
                          <xs:element name="Image" type="xs:string" />  
                          <xs:element name="Price" type="xs:decimal" />
                          <xs:element name="DiscountPrice" type="xs:decimal" />
                          <xs:element name="Size">
                            <xs:complexType>
                              <xs:simpleContent>
                                <xs:extension base="xs:string">
                                  <xs:attribute name="unit" type="xs:string" use="required" />
                                </xs:extension>
                              </xs:simpleContent>
                            </xs:complexType>
                          </xs:element>
                          <xs:element name="Quantity">
                            <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="Guarantee">
                            <xs:complexType>
                              <xs:simpleContent>
                                <xs:extension base="xs:unsignedByte">
                                  <xs:attribute name="unit" type="xs:string" use="required" />
                                </xs:extension>
                              </xs:simpleContent>
                            </xs:complexType>
                          </xs:element>
                          <xs:element name="Tags">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element maxOccurs="unbounded" name="Tag">
                                  <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:sequence>
                        <xs:attribute name="id" type="xs:int" use="required" />
                        <xs:attribute name="serialCode" type="xs:string" use="required" />
                        <xs:attribute name="priority" type="xs:unsignedByte" use="required" />
                        <xs:attribute name="visible" type="xs:boolean" use="required" />
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="id" type="xs:int" use="required" />
                  <xs:attribute name="visible" type="xs:boolean" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="id" type="xs:int" use="required" />
            <xs:attribute name="visible" type="xs:boolean" use="required" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="currency" type="xs:string" use="required" />
    </xs:complexType>
  </xs:element>
</xs:schema>


XML Transformatsioonid

Html, mis kuvab toidukaupasid, mis ei ole varjatud ("hidden")

<?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>Allahinnatud toidukaubad</title>
        </head>       
        <body>
          <xsl:for-each select="Catalog/Category">
            <xsl:if test="@id=3">
              <h2><xsl:value-of select="Name"/> </h2>
              <xsl:for-each select="SubCategory">
                <xsl:for-each select="Product">
                  <xsl:if test="@visible='true'">
                    <div>
                      <h3>
                        <xsl:value-of select="Name"/>
                      </h3>
                      <p>Hind: <xsl:value-of select="Price"/>&#160;<xsl:value-of select="/Catalog/@currency"/></p>
                      <p>Kogus: <xsl:value-of select="Size"/> <xsl:value-of select="Size/@unit"/></p> 
                    </div> 
                  </xsl:if>
                </xsl:for-each>
              </xsl:for-each>
            </xsl:if>
          </xsl:for-each>         
        </body>
      </html>  
    </xsl:template>
</xsl:stylesheet>


frameless


Kuvame kõik veebipoe tooted, järjestatuna soodsaimast hinnast alates

<?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>Head kaubad</title>
        <style type="text/css">
          table {border:1px solid black;}
          td {padding: 5px;}
          .headRow {background-color: skyblue; font-weight: bold;}
        </style>
      </head>
      <body>
        <table>
          <tr class="headRow">
            <td>Nimi</td>
            <td>Hind</td>
            <td>Kogus</td>
          </tr>               
        <xsl:for-each select="Catalog/Category/SubCategory/Product">
          <xsl:sort select="Price"/>
          <tr>
            <td>
              <xsl:value-of select="Name"/>
            </td>
            <td>
              <xsl:value-of select="Price"/>
            </td>
            <td>
              <xsl:value-of select="Quantity"/>
            </td>
          </tr> 
        </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>


frameless

Eemaldame XML-ist elemendid, mis on peiedtud (visibility=false)

<?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="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
  <xsl:template match="//Product[@visible='false']">  
  </xsl:template>
</xsl:stylesheet>