Meeskond: CoverMe: Difference between revisions
From ICO wiki
Jump to navigationJump to search
Line 223: | Line 223: | ||
===XSLT 1 (html)=== | ===XSLT 1 (html)=== | ||
<source lang="xml"> | |||
<?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" | ||
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" | xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> | ||
> | |||
<xsl:output method="html" indent="yes"/> | <xsl:output method="html" indent="yes"/> | ||
Revision as of 21:46, 17 April 2017
Meeskond: CoverMe
- Karit Kilgi
- Sten Kaasik
- Ragne Auling
- Silja Kralik
Idee
XML fail
XML
<?xml version="1.0" encoding="utf-8" ?> <employees>
<employee id="10012" available="false"> <personalCode>768-22-XXXX</personalCode> <image>https://yt3.ggpht.com/-V92UP8yaNyQ/AAAAAAAAAAI/AAAAAAAAAAA/zOYDMx8Qk3c/s900-c-k-no-mo-rj-c0xffffff/photo.jpg</image> <name> <firstName>Lucia</firstName> <middleName>J.</middleName> <lastName>Gaskill</lastName> </name> <gender>1</gender> <birthDate>1959-04-05</birthDate> <phone>904-366-8831</phone> <email>LuciaJGaskill@jourrapide.com</email> <contract id="1" startDate="2002-02-05" endDate="2008-03-15" status="0"> <company>Cadbury</company> <department>Service</department> <occupation>Cashier</occupation> <workload>40</workload> <extraWork id="1" startDate="2003-03-20" endDate="2003-04-20"> <company>Mr Fables</company> <task>Cleaner</task> <totalHours>80</totalHours> </extraWork> </contract> <contract id="2" startDate="2008-03-16" status="0"> <company>Cadbury</company> <department>Service</department> <occupation>Manager</occupation> <workload>40</workload> </contract> </employee> <employee id="10013" available="false"> <personalCode>769-48-XXXX</personalCode> <image></image> <name> <firstName>Martha</firstName> <lastName>Cornwell</lastName> </name> <gender>1</gender> <birthDate>1998-07-05</birthDate> <phone>123-456-7785</phone> <email>MarthaCornwall@jourrapide.com</email> <contract id="5" startDate="2001-03-21" status="0"> <company>Cadbury</company> <department>Service</department> <occupation>Servant</occupation> <workload>40</workload> </contract> </employee> <employee id="10234" available="true"> <personalCode>019-05-XXXX</personalCode> <image>http://weknowyourdreams.com/images/dog/dog-08.jpg</image> <name> <firstName>James</firstName> <lastName>Gibson</lastName> </name> <gender>2</gender> <birthDate>1957-08-02</birthDate> <phone>781-896-5862</phone> <email>JamesGibson@armyspy.com</email> <contract id="3" startDate="2016-12-27" status="1"> <company>Brilliant Home Designs</company> <department>Accounting</department> <occupation>Accountant</occupation> <workload>40</workload> </contract> </employee> <employee id="11454" available="true"> <personalCode>623-11-XXXX</personalCode> <image>https://www.mein-schoener-garten.de/sites/default/files/styles/inline_l/public/eichhoernchen-winter-2617791-blp-fotolia.jpg?itok=2UsYbm24</image> <name> <firstName>Elizabeth</firstName> <middleName>L.</middleName> <lastName>May</lastName> </name> <gender>1</gender> <birthDate>1997-01-12</birthDate> <phone>530-730-0818</phone> <email>ElizabethLMay@dayrep.com</email> <contract id="4" startDate="2015-05-23" status="1"> <company>Corinthian Designs</company> <department>Helpdesk</department> <occupation>Information and record clerk</occupation> <workload>20</workload> <extraWork id="1" startDate="2016-03-20" endDate="2016-03-22"> <company>Mr Fables</company> <task>Data processor</task> <totalHours>10</totalHours> </extraWork> </contract> </employee> <employee id="11455" available="true"> <personalCode>624-54-XXXX</personalCode> <image>http://www.miksike.ee/docs/referaadid2005/kiirgliblikas_evelin.jpg</image> <name> <firstName>Judy</firstName> <middleName>A.</middleName> <lastName>April</lastName> </name> <gender>1</gender> <birthDate>1970-02-22</birthDate> <phone>530-730-0818</phone> <email>JudyAApril@dayrep.com</email> <contract id="9" startDate="2010-07-23" status="0"> <company>Corinthian Designs</company> <department>Helpdesk</department> <occupation>Secretary</occupation> <workload>40</workload> <extraWork id="1" startDate="2016-03-20" endDate="2016-03-22"> <company>Mr Fables</company> <task>Data processor</task> <totalHours>16</totalHours> </extraWork> </contract> </employee> <employee id="11456" available="true"> <personalCode>1157-02-XXXX</personalCode> <image>https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS7I-9NIN5ys4TUSF61BYALQ_O_01w_XNNzQw5_mfueta0IQbvAqA</image> <name> <firstName>Tom</firstName> <lastName>Johnson</lastName> </name> <gender>0</gender> <birthDate>1972-02-02</birthDate> <phone>124-548-998</phone> <email>TomJohnson@dayrep.com</email> <contract id="14" startDate="1995-11-23" status="0"> <company>Corinthian Designs</company> <department>Analysis</department> <occupation>Analyst</occupation> <workload>40</workload> <extraWork id="1" startDate="2016-03-20" endDate="2016-03-25"> <company>Mr Fables</company> <task>Data processor</task> <totalHours>30</totalHours> </extraWork> </contract> </employee>
</employees>
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="employees"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" maxOccurs="unbounded" name="employee"> <xs:complexType> <xs:sequence> <xs:element name="personalCode" type="xs:string" nillable="false"/> <xs:element name="image" type="xs:string"/> <xs:element name="name"> <xs:complexType> <xs:sequence> <xs:element name="firstName" type="xs:string" /> <xs:element minOccurs="0" maxOccurs="unbounded" name="middleName" type="xs:string" /> <xs:element name="lastName" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="gender" type="xs:unsignedByte" nillable="false"/> <xs:element name="birthDate" type="xs:date" /> <xs:element name="phone" type="xs:string" /> <xs:element name="email" type="xs:string" /> <xs:element minOccurs="0" maxOccurs="unbounded" name="contract"> <xs:complexType> <xs:sequence> <xs:element name="company" type="xs:string" /> <xs:element name="department" type="xs:string" /> <xs:element name="occupation" type="xs:string" /> <xs:element name="workload" type="xs:unsignedByte" /> <xs:element minOccurs="0" maxOccurs="unbounded" name="extraWork"> <xs:complexType> <xs:sequence> <xs:element name="company" type="xs:string" /> <xs:element name="task" type="xs:string" /> <xs:element name="totalHours" type="xs:unsignedByte" /> </xs:sequence> <xs:attribute name="id" type="xs:unsignedInt" use="required" /> <xs:attribute name="startDate" type="xs:date" use="required" /> <xs:attribute name="endDate" type="xs:date" use="optional" /> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="id" type="xs:unsignedInt" use="required" /> <xs:attribute name="startDate" type="xs:date" use="required" /> <xs:attribute name="endDate" type="xs:date" use="optional" /> <xs:attribute name="status" type="xs:unsignedByte" use="required" /> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="id" type="xs:unsignedInt" use="required" /> <xs:attribute name="available" type="xs:boolean" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element>
</xs:schema>
XSLT 1 (html)
<source lang="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="html" indent="yes"/>
<xsl:template match="/"> <html> <head> <title>Employees</title> <style> </style> </head> <body>
Employees
<xsl:for-each select ="/employees/employee"> </xsl:for-each>ID | First name | Last name | Company | Present occupation | Available for extra work | Image |
---|---|---|---|---|---|---|
<xsl:value-of select="@id"/> | <xsl:value-of select="name/firstName"/> | <xsl:value-of select="name/lastName"/> |
<xsl:if test="contract/@endDate = 0"></xsl:if><xsl:value-of select="contract/company"/> |
<xsl:value-of select="contract/occupation"/> |
<xsl:choose> <xsl:when test="@available = 'true' "> Yes </xsl:when> <xsl:otherwise> No </xsl:otherwise> </xsl:choose> |
<xsl:choose> <xsl:when test="not(normalize-space(image)=)"> <img width="150" height="95" src="{image}"/> </xsl:when> <xsl:otherwise> Image not available </xsl:otherwise> </xsl:choose> |
</body> </html> </xsl:template>
</xsl:stylesheet>
XSLT 2 (xml)
<source lang="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="/"> <xsl:element name="contracts"> <xsl:for-each select="//employee"> <xsl:sort select="contract/@id"/> <xsl:for-each select="contract"> <xsl:element name="contract">
<xsl:attribute name="id"> <xsl:value-of select="@id"/> </xsl:attribute> <xsl:attribute name="startDate"> <xsl:value-of select="@startDate"/> </xsl:attribute> <xsl:attribute name="endDate"> <xsl:value-of select="@endDate"/> </xsl:attribute> <xsl:attribute name="status"> <xsl:value-of select="@status"/> </xsl:attribute> <xsl:element name="employee"> <xsl:attribute name="id"> <xsl:value-of select="../@id"/> </xsl:attribute> <xsl:attribute name="available"> <xsl:value-of select="../@available"/> </xsl:attribute> <xsl:copy-of select="../name"/> <xsl:copy-of select="../personalCode"/> </xsl:element>
<xsl:copy-of select="*"></xsl:copy-of>
</xsl:element> </xsl:for-each> </xsl:for-each> </xsl:element> </xsl:template>
</xsl:stylesheet>