Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoikLectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Goik Martin
GoikLectures
Commits
40ddb20f
Commit
40ddb20f
authored
10 years ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
Final remarks
parent
2d9d98ac
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Sda1/Etest/Xslt1/XsltSolution/person2user.xsl
+5
-13
5 additions, 13 deletions
Sda1/Etest/Xslt1/XsltSolution/person2user.xsl
Sda1/Etest/Xslt1/user.xhtml
+29
-15
29 additions, 15 deletions
Sda1/Etest/Xslt1/user.xhtml
Sda1/Etest/Xslt1/userSolution.xhtml
+45
-0
45 additions, 0 deletions
Sda1/Etest/Xslt1/userSolution.xhtml
with
79 additions
and
28 deletions
Sda1/Etest/Xslt1/XsltSolution/person2user.xsl
+
5
−
13
View file @
40ddb20f
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Sda1/Etest/Xslt1/user.xhtml
+
29
−
15
View file @
40ddb20f
...
...
@@ -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>
This diff is collapsed.
Click to expand it.
Sda1/Etest/Xslt1/userSolution.xhtml
0 → 100644
+
45
−
0
View file @
40ddb20f
<?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>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment