XML technologies / XSLT / XSLT 3.0 / XSLT streaming / First steps with XSLT streaming / xsl:mode on-no-match / on-no-match="shallow-copy"
Exercise 2
Use the mode on-no-match="shallow-copy", to rename the city element and the attribute value from openWeather.xml to stadt and wert, respectively. The rest of the document should be copied to the output unchanged. See the following code example :
Code example: required output for exercise 2 (excerpt).
<cityWeather>
<current>
<stadt id="2950159" name="Berlin"/>
<TEMP value="284.15" min="284.15" max="284.15" unit="kelvin"/>
<humidity wert="76" unit="%"/>
<pressure wert="1031" unit="hPa"/>
<wind>
<speed wert="3.1" name="Light breeze"/>
<gusts/>
<direction wert="150" code="SSE" name="South-southeast"/>
</wind>
<clouds wert="0" name="clear sky"/>
<visibility/>
<precipitation mode="no"/>
<weather number="800" wert="Sky is Clear" icon="01d"/>
<lastupdate wert="2015-12-08T11:20:00"/>
</current>
...
</cityWeather>The transformation renamed city to stadt and value to wert.
Use the transformation scenario [Übung 2] on-no-match="shallow-copy" (XML >> XML) (see the notes on the exercises) and the following XSLT file:
Code example: stylesheet for exercise 2 on xsl:mode on-no-match="shallow-copy".
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs math" version="3.0">
<!--AUFGABE: Nutzen Sie on-no-match="shallow-copy", um das Element city und das Attribut @value umzubenennen. Der Rest der XML-Datei soll unverändert in den Output übernommen werden. -->
<!--TODO: Streaming-Modus und on-no-match definieren.-->
<!--TODO: Entsprechende Templates anlegen.-->
</xsl:stylesheet>Extension
Write another template, which renames the attribute name of the city element to ortsname.
What happens? And why?
Solution
The complete output XML and the solution stylesheet can be found under Solutions to Exercise 2 — xsl:mode on-no-match="shallow-copy".