-
Notifications
You must be signed in to change notification settings - Fork 4
/
list.xsl
47 lines (40 loc) · 1.29 KB
/
list.xsl
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:kit="https://hananils.de/xslt/kit">
<!--
* hana+nils · Büro für Gestaltung
* https://hananils.de · buero@hananils.de
-->
<!--
* Kit: List
*
* This template combines nodes with a separator, e. g. creating a comma-separated
* list from a node set. It's possible to apply a template to the list item using
* the `kit:list-item` mode.
*
* # Example usage
*
* <xsl:apply-templates select="item" mode="kit:list" />
*
* # Parameters
*
* - separator
* The separator used to append items, defaults to a comma and space
* - separator-last
* The separator used to append the last item, defaults to a comma and space
-->
<xsl:template match="*" mode="kit:list">
<xsl:param name="separator" select="', '" />
<xsl:param name="separator-last" select="', '" />
<xsl:choose>
<xsl:when test="position() != 1 and position() != last()">
<xsl:value-of select="$separator" />
</xsl:when>
<xsl:when test="position() != 1 and position() = last()">
<xsl:value-of select="$separator-last" />
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="." mode="kit:list-item" />
</xsl:template>
</xsl:stylesheet>