RK

From ICO wiki
Revision as of 23:12, 15 March 2017 by Rkivinur (talk | contribs) (Created page with "== Meeskond == Raido Kivinurm == Esimene osa == === XML === <pre> <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="andmedHtml.xslt"?> <!--<?xml-...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Meeskond

Raido Kivinurm

Esimene osa

XML

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="andmedHtml.xslt"?>
<!--<?xml-stylesheet type="text/xsl" href="andmedXml.xslt"?>-->
<!-- Computer hardware "middleman"-->
<Hardware>
   <!-- Company that offers following item -->
   <Company code="12494674">
      <Name>Arvutitark OÜ</Name>
      <Address>
         <Country>Estonia</Country>
         <State>Harjumaa</State>
         <City>Tallinn</City>
         <AadressLine></AadressLine>
      </Address>
   </Company>
   
   <!-- Components they offer -->
   <Components>
      <Component type="Processor" shortName="CPU">
         <Item>
            <Name productcode="BX80646I74790K"><![CDATA[I7 4790K]]></Name>
            <Manufacturer>Intel</Manufacturer>
            <Price validFrom="2017-01-01" validUntil="2017-06-01">
               <Amount>350</Amount>
               <Currency>EUR</Currency>
               <Description><![CDATA[SUPER SALE!!!]]></Description>
            </Price>
            <CustomInfo>
               <InfoLine name="Socket Type"><![CDATA[LGA 1150]]></InfoLine>
               <InfoLine name="TDP"><![CDATA[84W]]></InfoLine>
            </CustomInfo>
            <Image><![CDATA[https://images10.newegg.com/ProductImage/19-117-369-02.jpg]]></Image>           
         </Item>
         
         <Item>
            <Name productcode="YD1700BBAEBOX"><![CDATA[Ryzen 7 1700]]></Name>
            <Manufacturer>AMD</Manufacturer>
            <Price validFrom="2017-03-01" validUntil="2017-05-05">
               <Amount>390</Amount>
               <Currency>EUR</Currency>
               <Description><![CDATA[ALL NEW CPU HAS "RYZEN"]]></Description>
            </Price>
            <Image><![CDATA[https://www.bhphotovideo.com/images/images1000x1000/amd_yd1700bbaebox_ryzen_7_1700_am4_1322539.jpg]]></Image>
        <CustomInfo>
          <InfoLine name="# of Cores"><![CDATA[8]]></InfoLine>
          <InfoLine name="Frequency"><![CDATA[3.0 GHz]]></InfoLine>
          <InfoLine name="Socket Type"><![CDATA[AM4]]></InfoLine>
          <InfoLine name="TDP"><![CDATA[65W]]></InfoLine>
        </CustomInfo>
         </Item> 
      </Component>
      
      <Component type="Power supply" shortName="PSU">
         <Item>
        <Image><![CDATA[http://www.enermax.pl/uploads/pics/maxpro01.png]]></Image>
            <Name productcode="EMP500AGT"><![CDATA[MaxPro 500]]></Name>
            <Manufacturer>Enermax</Manufacturer>
            <CustomInfo>
               <InfoLine name="Power"><![CDATA[500W]]></InfoLine>
               <InfoLine name="Efficiency"><![CDATA[80 Plus]]></InfoLine>
            </CustomInfo>
        <Price validFrom="2017-02-03" validUntil="2017-06-03">
          <Amount>55.50</Amount>
          <Currency>USD</Currency>
          <Description><![CDATA[]]></Description>
        </Price>
         </Item>
      </Component>   
      
      <Component type="Monitor">
         <Item>
            <Name productcode="210-AICW"><![CDATA[UltraSharp U2717D]]></Name>
            <Manufacturer>Dell</Manufacturer>
            <Price validFrom="2017-08-01" validUntil="2018-01-01">
               <Amount>450</Amount>
               <Currency>EUR</Currency>
               <Description><![CDATA[Be ready or be square]]></Description>
            </Price>
            <Image><![CDATA[http://www.gadgetreview.com/wp-content/uploads/2016/07/Dell-U2717D-Monitor-Design.jpg]]></Image>
        <CustomInfo>
          <InfoLine name="Display size"><![CDATA[27'']]></InfoLine>
          <InfoLine name="Resolution"><![CDATA[WQHD 2560×1440]]></InfoLine>
          <InfoLine name="HDMI"><![CDATA[Yes]]></InfoLine>
          <InfoLine name="Thunderbolt"><![CDATA[No]]></InfoLine>
        </CustomInfo>
         </Item>
      </Component>
      
      <Component type="Storage">
         <Item>
            <Name productcode="MZ-75E250B/EU"><![CDATA[850 EVO 250GB SATA 6Gbit/s]]></Name>
            <Manufacturer>Samsung</Manufacturer>
            <Price validFrom="2017-01-01" validUntil="2017-02-01">
               <Amount>500</Amount>
               <Currency>Bottle cap</Currency>
               <Description><![CDATA[Extra cheap. Get your caps ready!]]></Description>
            </Price>
            <CustomInfo>
               <InfoLine name="Capacity"><![CDATA[250GB]]></InfoLine>
               <InfoLine name="Size"><![CDATA[2.5'']]></InfoLine>
            </CustomInfo>
            <Image><![CDATA[https://images-na.ssl-images-amazon.com/images/I/71gkS5vep8L._SL1500_.jpg]]></Image>
         </Item>
      </Component>
      
   </Components>
</Hardware>

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="Hardware">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Company" minOccurs="1" maxOccurs="1">
          <xs:complexType>
            <xs:all>
              <xs:element name="Name" type="xs:string" />
              <xs:element name="Address">
                <xs:complexType>
                  <xs:all>
                    <xs:element name="Country" type="xs:string" />
                    <xs:element name="State" type="xs:string" />
                    <xs:element name="City" type="xs:string" />
                    <xs:element name="AadressLine" type="xs:string"/>
                  </xs:all>
                </xs:complexType>
              </xs:element>
            </xs:all>
            <xs:attribute name="code" type="xs:long" use="required" />
          </xs:complexType>
        </xs:element>
        
        <xs:element name="Components">
          <xs:complexType>
            <xs:sequence>
              <xs:element minOccurs="1" maxOccurs="unbounded" name="Component">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element minOccurs="1" maxOccurs="unbounded" name="Item">
                      <xs:complexType>
                        <xs:all>
                          <xs:element name="Name">
                            <xs:complexType>
                              <xs:simpleContent>
                                <xs:extension base="xs:string">
                                  <xs:attribute name="productcode" type="xs:string"/>
                                </xs:extension>
                              </xs:simpleContent>
                            </xs:complexType>
                          </xs:element>
                          <xs:element name="Manufacturer" type="xs:string" />
                          <xs:element name="Price">
                            <xs:complexType>
                              <xs:all>
                                <xs:element name="Amount" type="positiveDecimal"/>
                                <xs:element name="Currency" type="currencyType"/>
                                <xs:element name="Description" type="description" />
                              </xs:all>
                              <xs:attribute name="validFrom" type="xs:date" use="optional" />
                              <xs:attribute name="validUntil" type="xs:date" use="optional" />
                            </xs:complexType>
                          </xs:element>
                          <xs:element name="CustomInfo">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element maxOccurs="unbounded" name="InfoLine">
                                  <xs:complexType>
                                    <xs:simpleContent>
                                      <xs:extension base="xs:string">
                                        <xs:attribute name="name" type="description" use="required" />
                                      </xs:extension>
                                    </xs:simpleContent>
                                  </xs:complexType>
                                </xs:element>
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>
                          <xs:element name="Image" type="xs:string" />
                        </xs:all>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="type" use="required" type="componentType"/>
                  <xs:attribute name="shortName" type="xs:string" use="optional" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:simpleType name="componentType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Processor"/>
      <xs:enumeration value="Power supply"/>
      <xs:enumeration value="Videocard"/>
      <xs:enumeration value="Monitor"/>
      <xs:enumeration value="Storage"/>
      <xs:enumeration value="Motherboard"/>
      <xs:enumeration value="Cooler"/>
      <xs:enumeration value="Case"/>
      <xs:enumeration value="Other"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="currencyType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="EUR"/>
      <xs:enumeration value="USD"/>
      <xs:enumeration value="RUB"/>
      <xs:enumeration value="IRR"/>
      <xs:enumeration value="Bottle cap"/>
    </xs:restriction>
  </xs:simpleType>
  
  <xs:simpleType name="positiveDecimal">
    <xs:restriction base="xs:decimal">
      <xs:minInclusive value="0"/>
    </xs:restriction>
  </xs:simpleType>
  
  <xs:simpleType name="description">
    <xs:restriction base="xs:string">
      <xs:maxLength value="256"/>
    </xs:restriction>
  </xs:simpleType>
</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"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  <xsl:output method="html" indent="yes"/>
  <xsl:template match="/">
    <html>
      <body>
        <xsl:variable name="company" select="/Hardware/Company"/>
        <xsl:variable name="companyName" select="$company/Name"/>
        <xsl:variable name="country" select="$company/Address/Country"/>
        <xsl:variable name="state" select="$company/Address/State"/>
        <xsl:variable name="aLine" select="$company/Address/AadressLine"/>
        <xsl:variable name="fullAdress" select="concat($country,', ',$state,', ', $aLine)"/>
        <h2>
          <xsl:value-of select="$companyName"/>
          <br/>
          <xsl:value-of select="$fullAdress"/>
        </h2>
        <xsl:for-each select="/Hardware/Components/Component">
          <h3>
            <xsl:value-of select="@type"/>
            <xsl:if test="@shortName">
              <xsl:text> (</xsl:text>
              <xsl:value-of select="@shortName"/>
              <xsl:text>)</xsl:text>
            </xsl:if>
          </h3>
          <table>
            <tr>
              <xsl:for-each select="Item">
                <td>
                  <xsl:variable name="imageTitle" select="concat(Price/Description, ' ', Price/Amount,Price/Currency)"/>
                  <xsl:variable name="start" select="Price/@validFrom"/>
                  <xsl:variable name="end" select="Price/@validUntil"/>
                  <p>
                    <xsl:value-of select="Manufacturer"/>
                    <xsl:text> - </xsl:text>
                    <xsl:value-of select="Name"/>
                  </p>
                  <p style="font-size: 50%;">
                    <xsl:value-of select="Name/@productcode"/>
                  </p>
                  <img src="{Image}" title="{$imageTitle}" width="250" height="250" />
                  <table>
                    <tbody>
                      <xsl:for-each select="CustomInfo/InfoLine">
                        <tr>
                          <td style="width:100px; font-weight:bold">
                            <xsl:value-of select="@name"/>
                          </td>
                          <td style="width:150px">
                          <xsl:choose>
                            <xsl:when test=". = 'Yes'">
                              <xsl:text>✔</xsl:text>
                            </xsl:when>
                            <xsl:when test=". = 'No'">
                              <xsl:text>✖</xsl:text>
                            </xsl:when>
                            <xsl:otherwise>
                              <xsl:value-of select="."/>
                            </xsl:otherwise>
                          </xsl:choose>
                          </td>
                        </tr>
                      </xsl:for-each>
                    </tbody>                  
                  </table>
                </td>
              </xsl:for-each>
            </tr>
          </table>
          <hr/>
        </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"/>
    <xsl:template match="/">
      <Root>
        <ComponentTypes>
          <xsl:for-each select="Hardware/Components/Component">
            <xsl:variable name="count" select="count(Item)"/>
            <Type amount="{$count}">
              <xsl:value-of select="@type"/>
            </Type>
          </xsl:for-each>
        </ComponentTypes>
        <xsl:variable name="seller" select="Hardware/Company/Name"/>
        <Components>
          <xsl:for-each select="Hardware/Components/Component/Item">
            <Component>
              <xsl:variable name="currency" select="Price/Currency"/>
              <xsl:variable name="Manufacturer" select="Manufacturer"/>
              <Name company="{$Manufacturer}">
                <xsl:value-of select="Name"/>
              </Name>
              <Seller>
                <xsl:value-of select="$seller"/>
              </Seller>
              <Price curreny="{$currency}">
                <xsl:value-of select="Price/Amount"/>
              </Price>
              <ImageUrl>
                <xsl:value-of select="Image"/>
              </ImageUrl>
              <xsl:choose>
                <xsl:when test="$currency='Bottle cap'">
                  <Warning>Only for sale in Wastelands!</Warning>
                </xsl:when>
                <xsl:when test="$currency!='EUR'">
                 <Warning>Not for sale in EU!</Warning>
                </xsl:when>
              </xsl:choose>
            </Component>
          </xsl:for-each>
        </Components>
      </Root>
    </xsl:template>
</xsl:stylesheet>