1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
~/devel/Perl/XML$ cat books.xml
<library>
<books>
<book>
<name>Programming Perl</name>
<has_camel_on_cover>true</has_camel_on_cover>
</book>
<book>
<name>Am Ende war die Tat</name>
<has_camel_on_cover>false</has_camel_on_cover>
</book>
</books>
</library>
~/devel/Perl/XML$ cat books.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="//books">
<NewRootElement>
<xsl:for-each select="book">
<StringMatching>
<xsl:choose>
<xsl:when test="has_camel_on_cover = 'true'">
<xsl:text>🐪:</xsl:text>
</xsl:when>
<xsl:when test="has_camel_on_cover = 'false'">
<xsl:text>no 🐪:</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>otherwise:</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="name" />
</StringMatching>
<BoolEvaluation>
<xsl:choose>
<xsl:when test="has_camel_on_cover">
<xsl:text>🐪:</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>no 🐪:</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="name" />
</BoolEvaluation>
</xsl:for-each>
</NewRootElement>
</xsl:template>
</xsl:stylesheet>
~/devel/Perl/XML$ xsltproc books.xslt books.xml
<?xml version="1.0" encoding="utf-8"?>
<NewRootElement>
<StringMatching>🐪:Programming Perl</StringMatching>
<BoolEvaluation>🐪:Programming Perl</BoolEvaluation>
<StringMatching>no 🐪:Am Ende war die Tat</StringMatching>
<BoolEvaluation>🐪:Am Ende war die Tat</BoolEvaluation>
</NewRootElement>
bernhard@bernhard-Aspire-A515-57:~/devel/Perl/XML$
2024-11-17T16:09:18 barney[...]In der Praxis benutze ich XML::LibXSLT. Ehrlich gesagt, habe ich auch nicht getestet ob da xsl:import-schema tut. Ich bin davon ausgegangen dass die Anweisung unterstützt wird.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="/RootElement/Structure1">
<NewRootElement>
<xsl:for-each select="Array1">
<TrueOrNotTrueArray>
<!-- as="xs:integer" does not seem to cast to integer. So call number() explicitly -->
<xsl:variable name="my_int" select="number(.)"/>
<xsl:choose>
<xsl:when test="$my_int">
<xsl:text>⊨ TRUE:</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>⊭ NOT TRUE:</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$my_int" />
<xsl:text>,</xsl:text>
<xsl:value-of select="$my_int + 100" />
</TrueOrNotTrueArray>
</xsl:for-each>
</NewRootElement>
</xsl:template>
</xsl:stylesheet>