Blogify: Difference between revisions
From ICO wiki
Jump to navigationJump to search
Created page with "== Meeskond == * Hando Laasmägi * Tarvo Tammejuur * Cathy Toomast * Tõnn Vaher == Idee == == XML fail == <source lang="xml"> <?xml version="1.0" encoding="utf-8" ?> <Mai..." |
No edit summary |
||
Line 4: | Line 4: | ||
* Cathy Toomast | * Cathy Toomast | ||
* Tõnn Vaher | * Tõnn Vaher | ||
== XML fail == | == XML fail == |
Revision as of 22:11, 20 March 2017
Meeskond
- Hando Laasmägi
- Tarvo Tammejuur
- Cathy Toomast
- Tõnn Vaher
XML fail
<?xml version="1.0" encoding="utf-8" ?>
<Main>
<Posts>
<Post PostId="1" UserId="1" Date="2015-01-13T07:25:15" Title="My trip to Norway">
<Content><![CDATA[Blog post content.]]></Content>
<Comments>
<Comment UserId="2" Date="2015-01-14T13:55:33" Title="I am so envious!!!">
<Content><![CDATA[I wish i had the time to do those cool things]]></Content>
</Comment>
<Comment UserId="3" Date="2015-02-11T19:24:22" Title="Prr... So cold out there">
<Content><![CDATA[I don't know how you managed to stay alive there...]]></Content>
</Comment>
</Comments>
</Post>
<Post PostId="2" UserId="1" Date="2016-03-14T10:24:12" Title="My summer in Romania">
<Content><![CDATA[Blog post content..]]></Content>
<Comments>
<Comment UserId="3" Date="2017-03-14T11:21:34" Title="Home of Dracula?!">
<Content><![CDATA[So did you meat the charming beast out in the mountains?]]></Content>
</Comment>
<Comment UserId="2" Date="2017-03-15T12:56:11" Title="Do they use Euros there?">
<Content><![CDATA[Do they have their own money or are they using Euros?]]></Content>
</Comment>
<Comment UserId="3" Date="2017-03-16T19:22:54" Title="Why u so poor?">
<Content><![CDATA[Romania is for people who can't afford Greece?!]]></Content>
</Comment>
</Comments>
</Post>
<Post PostId="3" UserId="2" Date="2017-03-16T11:33:55" Title="Our love in Berlin">
<Content><![CDATA[Blog post content.]]></Content>
<Comments>
<Comment UserId="1" Date="2017-03-19T16:23:12" Title="Such love, such lies...">
<Content><![CDATA[I know all your secrets and all about Mark]]></Content>
</Comment>
</Comments>
</Post>
</Posts>
<Users>
<User UserId="1" Username="Hunter241" Firstname="Thomas" Surname="Stansfield" Email="tommy.stansfield@gmail.com">
<Description><![CDATA[I am a tough old man standing out for my country]]></Description>
</User>
<User UserId="2" Username="ToughChick53" Firstname="Irene" Surname="Kennedy" Email="irene@cia.gov">
<Description><![CDATA[Recently I have been feeling a little down because of the death of my mentor and all those attacks against me.]]></Description>
</User>
<User UserId="3" Username="IronMan" Firstname="Mitch" Surname="Rapp" Email="eyeinthemiddleeast@hotmail.com">
<Description><![CDATA[I have been, where few American men have been.]]></Description>
</User>
</Users>
</Main>
XSD fail
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Main">
<xs:complexType>
<xs:sequence>
<xs:element name="Posts">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Post">
<xs:complexType>
<xs:sequence>
<xs:element name="Content" type="xs:string" />
<xs:element name="Comments">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Comment">
<xs:complexType>
<xs:sequence>
<xs:element name="Content" type="xs:string" />
</xs:sequence>
<xs:attribute name="UserId" type="xs:unsignedInt" use="required" />
<xs:attribute name="Date" type="xs:dateTime" use="required" />
<xs:attribute name="Title" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="PostId" type="xs:unsignedInt" use="required" />
<xs:attribute name="UserId" type="xs:unsignedInt" use="required" />
<xs:attribute name="Date" type="xs:dateTime" use="required" />
<xs:attribute name="Title" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Users">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="User">
<xs:complexType>
<xs:sequence>
<xs:element name="Description" type="xs:string" />
</xs:sequence>
<xs:attribute name="UserId" type="xs:unsignedInt" use="required" />
<xs:attribute name="Username" type="xs:string" use="required" />
<xs:attribute name="Firstname" type="xs:string" use="required" />
<xs:attribute name="Surname" type="xs:string" use="required" />
<xs:attribute name="Email" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
1. XSLT - Posts
<?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 name="formatDate">
<xsl:param name="dateTime" />
<xsl:variable name="date" select="substring-before($dateTime, 'T')" />
<xsl:variable name="year" select="substring-before($date, '-')" />
<xsl:variable name="month" select="substring-before(substring-after($date, '-'), '-')" />
<xsl:variable name="day" select="substring-after(substring-after($date, '-'), '-')" />
<xsl:value-of select="concat($day, '.', $month, '.', $year)" />
</xsl:template>
<xsl:template match="/">
<html>
<body>
<h1>Blog posts!</h1>
<xsl:for-each select="/Main/Posts/Post">
<h2>
<xsl:value-of select="@Title"/> (
<xsl:call-template name="formatDate">
<xsl:with-param name="dateTime" select="@Date" />
</xsl:call-template>
)
</h2>
<p>
<xsl:value-of select="Content"/>
</p>
<h3>Comments</h3>
<ol>
<xsl:for-each select="Comments/Comment">
<li>
<b>
<xsl:value-of select="@Title"/>
</b>
(
<xsl:call-template name="formatDate">
<xsl:with-param name="dateTime" select="@Date" />
</xsl:call-template>
)
<p>
<xsl:value-of select="Content"/>
</p>
</li>
<!--Ends comments list-->
</xsl:for-each>
</ol>
<!--Ends posts list-->
</xsl:for-each>
<hr></hr>
<h2>
<u>Comments from user IronMan</u>
</h2>
<ol>
<xsl:for-each select="/Main/Posts/Post/Comments/Comment">
<xsl:if test="@UserId = 3">
<li>
<xsl:value-of select="@Title"/>
(
<xsl:call-template name="formatDate">
<xsl:with-param name="dateTime" select="@Date" />
</xsl:call-template>
)
<br></br>
<xsl:value-of select="Content"/>
</li>
</xsl:if>
</xsl:for-each>
</ol>
<hr></hr>
<h2>
<u>
Showing all posts with comments,<br></br>
where day of week of published comment is less than 15, and sorted in descending order
</u>
</h2>
<xsl:for-each select="/Main/Posts/Post">
<xsl:for-each select="Comments/Comment">
<xsl:sort select="@Date" order="descending"/>
<xsl:variable name="date" select="substring-before(@Date, 'T')" />
<xsl:variable name="day" select="substring-after(substring-after($date, '-'), '-')" />
<xsl:if test="$day < 15">
<h2>
<xsl:value-of select="@Title"/>
(
<xsl:call-template name="formatDate">
<xsl:with-param name="dateTime" select="@Date" />
</xsl:call-template>
)
</h2>
<p>
<xsl:value-of select="Content"/>
</p>
<h3>Comments</h3>
<ol>
<li>
<b>
<xsl:value-of select="@Title"/>
</b>
(
<xsl:call-template name="formatDate">
<xsl:with-param name="dateTime" select="@Date" />
</xsl:call-template>
)
<p>
<xsl:value-of select="Content"/>
</p>
</li>
</ol>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
2. XSLT - Users
<?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>
<body>
<h1>Blog Users!</h1>
<xsl:for-each select="/Main/Users/User">
<h2>
Username: <xsl:value-of select="@Username"/>
</h2>
<ul>
<li>
Firstname: <xsl:value-of select="@Firstname"/>
</li>
<li>
Surname: <xsl:value-of select="@Surname"/>
</li>
<li>
Email: <xsl:value-of select="@Email"/>
</li>
<li>
Description: <xsl:value-of select="Description"/>
</li>
</ul>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Tulemus
TODO