Løsn.forslag til eksamen i XML-teknologi (LO515D), våren 2006 (oppdatert).

Oppgave 1

a)

XSLT:

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

xsl:stylesheet version="1.0" xmlns:xsl=" xmlns:fo="

xsl:template match="/">

html

head

titleVærdata</title

</head

body

xsl:apply-templates select="vaerdata/vaer"/>

</body

</html

</xsl:template

xsl:template match="vaerdata/vaer">

h1Været i xsl:value-of select="by "/>

</h1

table border="0" cellpadding="3" cellspacing="0">

tr

th align="left">Tid</th

tdxsl:value-of select="tid"/</td

</tr

tr

th align="left">Temperatur</th

tdxsl:value-of select="temp"/</td

</tr

tr

th align="left">Vindstyrke</th

tdxsl:apply-templates select="vindstyrke"/>

</td

</tr

tr

th align="left">Varsel</th

tdxsl:value-of select="tekstvarsel"/</td

</tr

</table

</xsl:template

xsl:template match="vindstyrke">

xsl:value-of select="."/<xsl:text</xsl:text

xsl:value-of select="@maaleenhet"/>

</xsl:template

</xsl:stylesheet

b)

XSLT:

xsl:choose

xsl:when test="vindstyrke &lt; 3.4 ">

xsl:element name="beaufort"<xsl:textStille eller svak vind</xsl:text</xsl:element

/xsl:when

xsl:when test="vindstyrke &gt; 3.3 and vindstyrke &lt; 20.8 ">

xsl:element name="beaufort"<xsl:textBris eller kuling</xsl:text</xsl:element

</xsl:when

xsl:when test="vindstyrke &gt; 20.7 ">

xsl:element name="beaufort"<xsl:textStorm eller Orkan</xsl:text</xsl:element

</xsl:when

xsl:otherwisexsl:apply-templates select="vindstyrke"/>

</xsl:otherwise

</xsl:choose

c)

XSLT:

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

xsl:stylesheet version="1.0" xmlns:xsl=" xmlns:fo="

xsl:template match="/">

html

head

titleVærdata</title

</head

body

h1Trondheim</h1

table border="1" cellpadding="3" cellspacing="0">

tr

th align="left">Tid</th

th align="left">Temperatur</th

th align="left">Vindstyrke</th

</tr

xsl:apply-templates select="vaerdata/vaer"/>

</table

pbAntall målinger: </b

xsl:value-of select="count(vaerdata/vaer[by = 'Trondheim'])"/>

</p

</body

</html

</xsl:template

xsl:template match="vaerdata/vaer">

xsl:if test="by = 'Trondheim' ">

tr

tdxsl:value-of select="tid"/</td

tdxsl:value-of select="temp"/</td

td

xsl:apply-templates select="vindstyrke"/>

<!-- bruker her template-en fra oppg. a) for å få ut vindstyrken m/ att. -->

</td

</tr

</xsl:if

</xsl:template

</xsl:stylesheet

Oppgave 2

a)

XML-skjema:

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

xs:schema xmlns:xs=" elementFormDefault="qualified" attributeFormDefault="unqualified">

xs:complexType name="vaerType" mixed="true">

xs:sequence minOccurs="0" maxOccurs="unbounded">

xs:element ref="by"/>

xs:element ref="tid"/>

xs:element ref="temp"/>

xs:element ref="vindstyrke"/>

xs:element ref="tekstvarsel" minOccurs="0"/>

</xs:sequence

</xs:complexType

xs:element name="by" type="xs:string"/>

xs:element name="tid" type="xs:dateTime"/>

xs:element name="temp" type="xs:float"/>

xs:element name="vindstyrke">

xs:complexTypemixed="true"

xs:attribute name="maaleenhet" type="xs:string" use="required"/>

</xs:complexType

</xs:element

xs:element name="tekstvarsel" type="xs:string"/>

xs:element name="vaerdata">

xs:complexType

xs:sequence

xs:element name="vaer" type="vaerType" maxOccurs="unbounded"/>

</xs:sequence

</xs:complexType

</xs:element

</xs:schema

b) Se side 349 i læreboka. ("Enumeration")

c) Se side 333 i læreboka ("Mixed Content")

Oppgave 3

a)

DOM/JavaScript-kode:

varsel = root.lastChild

var nyttElement = xmlDoc.createElement("tekstvarsel")

var nyTekst = xmlDoc.createTextNode("Klar himmel, kald luft")

nyttElement.appendChild(nyTekst)

varsel.appendChild(nyttElement)

alert(varsel.xml)

b)

Antar her at root.firstChild.nextSibling er 'Bergen'-noden.

DOM/JavaScript -kode:

temperatur = root.firstChild.nextSibling.firstChild.nextSibling.nextSibling.firstChild

alert("Temperaturen var " + temperatur.xml + " grader")

c)

SVG-kode:

<?xml version="1.0" standalone="no"?>

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"

"

svg width="300px" height="300px" viewBox="0 0 300 300"

xmlns="

desc

Flaggets proposjoner:

Horisontalt: 6R 1H 2B 1h 12R=22

Vertikalt: 6R 1H 2B 1H 6R=16

</desc

g transform="translate(20,50)">

rect x="0" y="0" width="220" height="160"

fill="red" stroke="none" stroke-width="0"/>

rect x="0" y="60" width="220" height="40"

fill="white" stroke="none"/>

rect x="60" y="0" width="40" height="160"

fill="white" stroke="none"/>

rect x="0" y="70" width="220" height="20"

fill="blue" stroke="none"/>

rect x="70" y="0" width="20" height="160"

fill="blue" stroke="none"/>

g transform="translate(0,225)">

text id="TextElement" x="0" y="0"

font-family="Verdana" font-size="25"

fill="black" stroke="none">

17.mai

</text

</g

</g

</svg