diff --git a/Sda1/Etest/Xslt1/XsltSolution/person2user.xsl b/Sda1/Etest/Xslt1/XsltSolution/person2user.xsl index 5a57b389a44f6d3f23ed6b19455dcaf0dceadbe0..07d1c2c0df973e8028aa5decf49a12c68a87d735 100644 --- a/Sda1/Etest/Xslt1/XsltSolution/person2user.xsl +++ b/Sda1/Etest/Xslt1/XsltSolution/person2user.xsl @@ -8,11 +8,11 @@ <users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="user.xsd" > - <xsl:apply-templates select="person[@id]"/> + <xsl:apply-templates select="person[@id]"/> <!-- Selecting only <person> nodes having an @id attribute --> </users> </xsl:template> - <xsl:template match="person[@id]"> + <xsl:template match="person[@id]"> <!-- <person> elements without @id attribute cannot show up --> <user index="{position()}" uid="user_{@id}"> <uid> <xsl:value-of select="lastName"/> @@ -23,8 +23,9 @@ <xsl:value-of select="lastName"/> </fullName> <contact> - <xsl:choose> + <xsl:choose> <!-- <xsl:choose> acts like if(...) ... else if(...) ... else {} --> <xsl:when test="email"> + <!--<xsl:attribute ...> acts on the nearest non-XSL ancestor element (<contact>) --> <xsl:attribute name="type" select="'email'"/> <xsl:value-of select="email"/> </xsl:when> @@ -39,14 +40,5 @@ </contact> </user> </xsl:template> - - <!-- Just in case of forgotten rules. --> - <xsl:template match="*"> - <xsl:message> - <xsl:text>Error: No template matching element '</xsl:text> - <xsl:value-of select="name(.)"/> - <xsl:text>'</xsl:text> - </xsl:message> - </xsl:template> - + </xsl:stylesheet> \ No newline at end of file diff --git a/Sda1/Etest/Xslt1/user.xhtml b/Sda1/Etest/Xslt1/user.xhtml index d70b73468c89104058c629aca821de0a1ddaa808..1f2ced1da9d86d541ace1bc92b250ba96435b111 100644 --- a/Sda1/Etest/Xslt1/user.xhtml +++ b/Sda1/Etest/Xslt1/user.xhtml @@ -5,12 +5,24 @@ <title></title> </head> - <body><h2>Objective</h2><p>A list of persons being represented by an XML - document instance shall be transferred into a different XML - representation.</p><h2>Preparations</h2><p>Download XXX.zip and import it as - a project into your Eclipse workspace.</p><h2>Description</h2><p>The - imported Eclipse project contains the following sample document instance - <code>userData.xml</code>:</p><pre><persons + <body><h2>Objective</h2><p>An XML list of persons being represented by an + XML document instance shall be transformed into a different XML + representation. The idea is to turn a business description of persons into a + user database defining system logins.</p><h2>Preparations</h2><ol> + <li>Download <a + href="https://learn.mi.hdm-stuttgart.de/iliasData/goik/sdfweergdth45n3535nr3rn3Gff/xslt.zip">xslt.zip</a> + and import it as a project into your Eclipse workspace.</li> + + <li>Your resulting Project named Xslt contains a file + <code>personData.xml</code> and an XSLT skeleton file + <code>person2user.xsl</code>. Define an Xslt transformation scenario + which turns <code>personData.xml</code> into <code>user.xml</code> by + means of <code>person2user.xsl</code>. <span style="color: red;">Do not + overwrite the intended sample output data file + <code>userData.xml</code></span>.</li> + </ol><h2>Description</h2><p>The imported Eclipse project contains the + following sample document instance <code>personData.xml</code>:</p><pre + style="font-family:monospace;"><persons xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="person.xsd"> @@ -20,16 +32,19 @@ <phone>322-33434</phone> </person> - ... see your Eclipse workspace for further details + ... see your Eclipse workspace file personData.xml for further details -</persons></pre><p>We want to generate the following output:</p><pre><users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +</persons></pre><p>This file is valid with respect to + <code>person.xsd</code>. We want to generate the following result as being + shown in your <code>userData.xml</code> sample output file:</p><pre + style="font-family:monospace;"><users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="user.xsd"> <user index="1" uid="user_23"> <uid>White</uid> <fullName>Sue White</fullName> <contact type="phone">322-33434</contact> </user> - ... see your Eclipse workspace for further details + ... see your Eclipse workspace sample output file userData.xml for further details </users></pre><p>The following conditions shall be met:</p><ul> <li><person> entries without id attribute shall be excluded</li> @@ -50,12 +65,11 @@ <code><email></code> nor <code><phone></code> is present.</li> </ul></li> - </ul><p>Both input and output may be validated against - <code>person.xsd</code> and <code>user.xsd</code> - respectively.</p><h2>ToDo</h2><p>Start from provided file - <code>person2user.xsl</code> and extend it to implement the previously - described transformation. When you are finished just upload your file - <code>person2user.xsl</code>.</p><h2>Hints</h2><p>The function + </ul><p>The generated output file shall be valid with respect to + <code>user.xsd</code>.</p><h2>ToDo</h2><p>Start from + <code>person2user.xsl</code> and implement the previously described + transformation. When you are finished upload your final + <code>person2user.xsl</code> result.</p><h2>Hints</h2><p>The function <code>position()</code> returns the index of an element within a given node set.</p></body> </html> diff --git a/Sda1/Etest/Xslt1/userSolution.xhtml b/Sda1/Etest/Xslt1/userSolution.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..8638d76c126f8938d4438a88f060a1ccf09d1f7f --- /dev/null +++ b/Sda1/Etest/Xslt1/userSolution.xhtml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title></title> + </head> + + <body><h1>Solution</h1><p>A possible style sheet implementation + reads:</p><pre style="font-family:monospace;"> <xsl:template match="/persons"> + <users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="user.xsd" + > + <xsl:apply-templates select="person[@id]"/> <!-- Selecting only <person> nodes having an @id attribute --> + </users> + </xsl:template> + + <xsl:template match="person[@id]"> <!-- <person> elements without @id attribute cannot show up --> + <user index="{position()}" uid="user_{@id}"> + <uid> + <xsl:value-of select="lastName"/> + </uid> + <fullName> + <xsl:value-of select="firstName"/> + <xsl:text> </xsl:text> + <xsl:value-of select="lastName"/> + </fullName> + <contact> + <xsl:choose> <!-- <xsl:choose> acts like if(...) ... else if(...) ... else {} --> + <xsl:when test="email"> + <!--<xsl:attribute ...> acts on the nearest non-XSL ancestor element (<contact>) --> + <xsl:attribute name="type" select="'email'"/> + <xsl:value-of select="email"/> + </xsl:when> + <xsl:when test="phone"> + <xsl:attribute name="type" select="'phone'"/> + <xsl:value-of select="phone"/> + </xsl:when> + <xsl:otherwise> + <xsl:attribute name="type" select="'none'"/> + </xsl:otherwise> + </xsl:choose> + </contact> + </user> + </xsl:template></pre></body> +</html>