Meeskond "PhoneBook": Difference between revisions

From ICO wiki
Jump to navigationJump to search
Mraak (talk | contribs)
Tjuris (talk | contribs)
No edit summary
Line 1: Line 1:
== Meeskond ==
== Meeskond ==
* Lauri Jansen - wiki, XML
* Lauri Jansen - wiki, XML, schema
* Tanel Jüris
* Tanel Jüris - XSLT XML-i
* Madis Rääk
* Madis Rääk - XSLT html-i


== Idee ==
== Idee ==
Line 176: Line 176:


<pre>
<pre>
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Line 212: Line 211:
</xsl:template>
</xsl:template>
</xsl:stylesheet>
</xsl:stylesheet>
</pre>


Tulemus, kus on tähestikuliselt järjestatud tabelina nimi, aadress, lauatelefon ja mobiil:
<pre>
<html>
  <body>
    <h2>Phone book entries (a-z)</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Name</th>
        <th>Address</th>
        <th>Landline</th>
        <th>Mobile phone</th>
      </tr>
      <tr>
        <td> Linda  Kuusk </td>
        <td> Eesti ,
                Tallinn ,
                Akadeemia tee  28 </td>
        <td> 6359866 </td>
        <td> 56777521 </td>
      </tr>
      <tr>
        <td> Mart  Tamm </td>
        <td> Eesti ,
                Tartu ,
                Põllu  6 </td>
        <td> 7249959 </td>
        <td> 53345699 </td>
      </tr>
    </table>
  </body>
</html>
</pre>
</pre>


Line 219: Line 252:


<pre>
<pre>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
  <xsl:output method="xml" indent="yes"/>
 
  <xsl:template match="/">
    <xsl:element name ="contacts">
      <xsl:for-each select="contacts/contact">
        <xsl:element name="contact">
          <xsl:attribute name="id">
            <xsl:value-of select="@id" />
          </xsl:attribute>
        <xsl:copy-of select="names"/>
       
        <xsl:variable name ="default" select="phones/@default" />
       
        <xsl:for-each select = "phones/phone">
          <xsl:if test="$default = @id">
            <xsl:copy-of select="."/>
          </xsl:if>
        </xsl:for-each>
        </xsl:element>
      </xsl:for-each>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>
</pre>


Tulekul


XML, kus on alles ainult nimi ja vaikimisi telefoni number:
<pre>
<?xml version="1.0" encoding="utf-8"?>
<contacts>
  <contact id="1">
    <names>
      <first_name> Mart </first_name>
      <middle_names>
        <middle_name />
      </middle_names>
      <last_name> Tamm </last_name>
    </names>
    <phone type="landline" id="1"> 7249959 </phone>
  </contact>
  <contact id="2">
    <names>
      <first_name> Linda </first_name>
      <middle_names>
        <middle_name />
      </middle_names>
      <last_name> Kuusk </last_name>
    </names>
    <phone type="mobile" id="3"> 56777521 </phone>
  </contact>
</contacts>
</pre>
</pre>


== Log ==
== Log ==
=== 03.03.2012 ===
* XSLT XML transformatsiooni lisamine wikisse.


=== 03.02.2012 ===
=== 03.02.2012 ===
* XSLT lisamine wikisse. Viimased lihvimised hinde jaoks.
* XSLT html transformatsiooni lisamine wikisse. Viimased lihvimised hinde jaoks.


=== 28.02.2012 ===
=== 28.02.2012 ===

Revision as of 15:10, 3 March 2012

Meeskond

  • Lauri Jansen - wiki, XML, schema
  • Tanel Jüris - XSLT XML-i
  • Madis Rääk - XSLT html-i

Idee

Luua näidisteemades välja pakutud telefoniraamatu teenus kus:

  • kasutaja saab teenuses kontakte lisada ja kustutada
  • kasutaja saab kontaktide nime/telefoninumbri jne abil otsida
  • luua võimalus ühele kasutajale (või erinevatele kasutajagruppidele) maksimumpäringute hulga määramiseks

Kusjuures on olemas ka lisavõimalused:

  • luua võimalus kasutajatel oma kontaktibaase omavahel jagada
  • luua võimalus pakkuda kontaktibaasis leiduvate nimede järgi sobivaid nimesid

XML fail

Ülesande täitmiseks tuleb luua XML fail andmete edastamiseks, selle XML faili skeemifail ning paar kolm sobivat XSL faili loodud XML failis olevate andmete transformeerimiseks HTML formaati ja XML faili formaadi muutmiseks.

XML-il peab olema vähemalt 4 loogilist dimensiooni.

Lisaks tuleb kasutada 3-el dimensioonil attribuute, mis on enamat, kui lihtsalt ID.

XML


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

<contacts>
  <contact id="1">
    
    <names>
      <first_name> Mart </first_name>
      <middle_names>
        <middle_name></middle_name>
      </middle_names>
      <last_name> Tamm </last_name>
    </names>
    <addresses default="1">
      <address id="1">
        <country> Eesti </country>
        <county> Tartumaa </county>
        <town> Tartu </town>
        <street> Põllu </street>
        <house_nr> 6 </house_nr>
        <zip_code> 50210 </zip_code>
      </address>
      <address id="2">
        <country> Eesti </country>
        <county> Jõgevamaa </county>
        <town> Palamuse </town>
        <street> Oti Talu </street>
        <house_nr> </house_nr>
        <zip_code> 47292 </zip_code>
      </address>
    </addresses>
    <phones default="1">
      <phone type="landline" id="1"> 7249959 </phone>
      <phone type="skype" id="2"></phone>
      <phone type="mobile" id="3"> 53345699 </phone>
      <phone type="work" id="4"></phone>
      <phone type="other" id="5"></phone>
    </phones>
    <comments></comments>
  </contact>
  
  <contact id="2">
    <names>
      <first_name> Linda </first_name>
      <middle_names>
        <middle_name></middle_name>
      </middle_names>
      <last_name> Kuusk </last_name>
    </names>
    <addresses default="1">
      <address id="1">
        <country> Eesti </country>
        <county> Harjumaa </county>
        <town> Tallinn </town>
        <street> Akadeemia tee </street>
        <house_nr> 28 </house_nr>
        <zip_code> 12300 </zip_code>
      </address>
    </addresses>
    <phones default="3">
      <phone type="landline" id="1"> 6359866 </phone>
      <phone type="skype" id="2"></phone>
      <phone type="mobile" id="3"> 56777521 </phone>
      <phone type="work" id="4"></phone>
      <phone type="other" id="5"></phone>
    </phones>
    <comments></comments>
    
  </contact>
</contacts>

XML schema (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="contacts">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="contact">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="names">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="first_name" type="xs:string" />
                    <xs:element name="middle_names">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="middle_name" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <xs:element name="last_name" type="xs:string" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="addresses">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="address">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="country" type="xs:string" />
                          <xs:element name="county" type="xs:string" />
                          <xs:element name="town" type="xs:string" />
                          <xs:element name="street" type="xs:string" />
                          <xs:element name="house_nr" type="xs:string" />
                          <xs:element name="zip_code" type="xs:unsignedShort" />
                        </xs:sequence>
                        <xs:attribute name="id" type="xs:unsignedByte" use="required" />
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="default" type="xs:unsignedByte" use="required" />
                </xs:complexType>
              </xs:element>
              <xs:element name="phones">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="phone">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:string">
                            <xs:attribute name="type" type="xs:string" use="required" />
                            <xs:attribute name="id" type="xs:unsignedByte" use="required" />
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="default" type="xs:unsignedByte" use="required" />
                </xs:complexType>
              </xs:element>
              <xs:element name="comments" />
            </xs:sequence>
            <xs:attribute name="id" type="xs:unsignedByte" use="required" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

XSLT

Transformeerimine HTML formaati

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
  <h2>Phone book entries (a-z)</h2>
    <table border="1">
    <tr bgcolor="#9acd32">
	<th>Name</th>
	<th>Address</th>
	<th>Landline</th>
	<th>Mobile phone</th>
    </tr>
    <xsl:for-each select="contacts/contact">
    <xsl:sort select="names/first_name"/>
    <tr>
	<td>
	    <xsl:value-of select="names/first_name"/><xsl:text> </xsl:text> <!-- extra space -->
	    <xsl:value-of select="names/last_name"/>
	</td>
	<td>
	    <xsl:value-of select="addresses/address/country"/>,
	    <xsl:value-of select="addresses/address/town"/>,
	    <xsl:value-of select="addresses/address/street"/><xsl:text> </xsl:text> <!-- extra space -->
	    <xsl:value-of select="addresses/address/house_nr"/>
	</td>
	    <td><xsl:value-of select="phones/phone[@type='landline']"/></td>
	    <td><xsl:value-of select="phones/phone[@type='mobile']"/></td>
    </tr>
    </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>


Tulemus, kus on tähestikuliselt järjestatud tabelina nimi, aadress, lauatelefon ja mobiil:

<html>
  <body>
    <h2>Phone book entries (a-z)</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Name</th>
        <th>Address</th>
        <th>Landline</th>
        <th>Mobile phone</th>
      </tr>
      <tr>
        <td> Linda   Kuusk </td>
        <td> Eesti ,
                 Tallinn ,
                 Akadeemia tee   28 </td>
        <td> 6359866 </td>
        <td> 56777521 </td>
      </tr>
      <tr>
        <td> Mart   Tamm </td>
        <td> Eesti ,
                 Tartu ,
                 Põllu   6 </td>
        <td> 7249959 </td>
        <td> 53345699 </td>
      </tr>
    </table>
  </body>
</html>


XML faili formaadi muutmine

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:output method="xml" indent="yes"/>
  
  <xsl:template match="/">
    <xsl:element name ="contacts">
      <xsl:for-each select="contacts/contact">
        <xsl:element name="contact">
          <xsl:attribute name="id">
            <xsl:value-of select="@id" />
          </xsl:attribute>
        <xsl:copy-of select="names"/>
        
        <xsl:variable name ="default" select="phones/@default" />
        
        <xsl:for-each select = "phones/phone">
          <xsl:if test="$default = @id">
            <xsl:copy-of select="."/>
          </xsl:if>
        </xsl:for-each>
        </xsl:element>
      </xsl:for-each>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>


XML, kus on alles ainult nimi ja vaikimisi telefoni number:

<?xml version="1.0" encoding="utf-8"?>
<contacts>
  <contact id="1">
    <names>
      <first_name> Mart </first_name>
      <middle_names>
        <middle_name />
      </middle_names>
      <last_name> Tamm </last_name>
    </names>
    <phone type="landline" id="1"> 7249959 </phone>
  </contact>
  <contact id="2">
    <names>
      <first_name> Linda </first_name>
      <middle_names>
        <middle_name />
      </middle_names>
      <last_name> Kuusk </last_name>
    </names>
    <phone type="mobile" id="3"> 56777521 </phone>
  </contact>
</contacts>

Log

03.03.2012

  • XSLT XML transformatsiooni lisamine wikisse.

03.02.2012

  • XSLT html transformatsiooni lisamine wikisse. Viimased lihvimised hinde jaoks.

28.02.2012

  • XML täiendatud/parandatud versioon

27.02.2012

  • XML algne versioon ja wiki valmimine