1 |
<?xml version="1.0" encoding="UTF-8" ?> |
2 |
<!-- |
3 |
(c) 2007 by Intevation GmbH |
4 |
Author: Sascha L. Teichmann |
5 |
Converts |
6 |
<choice name="choice-0" options="foo:a;bar:b:s"/> |
7 |
to |
8 |
<choice> |
9 |
<bool name="choice-0-0" description="foo" value="a"/> |
10 |
<bool name="choice-0-1" description="bar" value="b" checked="s"/> |
11 |
</choice> |
12 |
--> |
13 |
<xsl:stylesheet version="1.0" |
14 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
15 |
xmlns:str="http://exslt.org/strings" |
16 |
extension-element-prefixes="str"> |
17 |
|
18 |
<xsl:output method="xml" encoding="UTF-8"/> |
19 |
|
20 |
<xsl:template name="itemize-value"> |
21 |
<xsl:param name="prefix"/> |
22 |
<xsl:param name="value"/> |
23 |
<xsl:for-each select="str:tokenize($value, ';')"> |
24 |
<xsl:variable name="num" select="count(preceding-sibling::*)"/> |
25 |
<bool> |
26 |
<xsl:attribute name="name"> |
27 |
<xsl:value-of select="concat($prefix, '-', $num)"/> |
28 |
</xsl:attribute> |
29 |
<xsl:variable name="tuple" select="str:tokenize(., ':')"/> |
30 |
<xsl:variable name="tuplelen" select="count($tuple)"/> |
31 |
<xsl:if test="$tuplelen > 0"> |
32 |
<xsl:attribute name="description"> |
33 |
<xsl:value-of select="$tuple[1]"/> |
34 |
</xsl:attribute> |
35 |
</xsl:if> |
36 |
<xsl:if test="$tuplelen > 1"> |
37 |
<xsl:attribute name="value"> |
38 |
<xsl:value-of select="$tuple[2]"/> |
39 |
</xsl:attribute> |
40 |
</xsl:if> |
41 |
<xsl:if test="$tuplelen > 2"> |
42 |
<xsl:attribute name="checked"> |
43 |
<xsl:value-of select="$tuple[3]"/> |
44 |
</xsl:attribute> |
45 |
</xsl:if> |
46 |
</bool> |
47 |
</xsl:for-each> |
48 |
</xsl:template> |
49 |
|
50 |
<xsl:template match="choice"> |
51 |
<choice> |
52 |
<!-- copy all attributes except 'value' --> |
53 |
<xsl:copy-of select="@*[local-name() != 'value']"/> |
54 |
|
55 |
<xsl:call-template name="itemize-value"> |
56 |
<xsl:with-param name="prefix"> |
57 |
<xsl:value-of select="@name"/> |
58 |
</xsl:with-param> |
59 |
<xsl:with-param name="value"> |
60 |
<xsl:value-of select="@value"/> |
61 |
</xsl:with-param> |
62 |
</xsl:call-template> |
63 |
</choice> |
64 |
</xsl:template> |
65 |
|
66 |
<!-- copy thru all other stuff --> |
67 |
<xsl:template match="@*|node()"> |
68 |
<xsl:copy> |
69 |
<xsl:apply-templates select="@*|node()"/> |
70 |
</xsl:copy> |
71 |
</xsl:template> |
72 |
|
73 |
</xsl:stylesheet> |