-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_capabilities.xsl
77 lines (64 loc) · 2.11 KB
/
get_capabilities.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:common="http://exslt.org/common">
<xsl:output method="xml"
encoding="UTF-8"
indent="yes"/>
<!--
get all capabilities for one device
send comments, questions to roland guelle <[email protected]>
-->
<xsl:param name="ua"></xsl:param>
<xsl:param name="id"></xsl:param>
<xsl:template match="/wurfl/devices">
<xsl:variable name="dID">
<xsl:choose>
<xsl:when test="$id != ''">
<xsl:value-of select="device[@id=$id]/@id"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="device[@user_agent=$ua]/@id"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="device[@id=$dID]/@id = false()">
<error>
UserAgent='<xsl:value-of select="$ua"/>' or ID='<xsl:value-of select="$id"/>' not found
</error>
</xsl:when>
<xsl:otherwise>
<!--
get all capabilities
-->
<xsl:variable name="duid">
<xsl:copy-of select="device[@id=$dID]/group/capability"/>
<xsl:call-template name="tid">
<xsl:with-param name="fall_back" select="device[@id=$dID]/@fall_back"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="duid_nodes" select="common:node-set($duid)"/>
<device>
<xsl:copy-of select="device[@id=$dID]/@*"/>
<xsl:for-each select="$duid_nodes/capability">
<xsl:sort select="@name"/>
<xsl:if test="not(@name = preceding-sibling::capability/@name)">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</device>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="tid">
<xsl:param name="fall_back"/>
<xsl:if test="$fall_back != ''">
<xsl:copy-of select="device[@id = $fall_back]/group/capability"/>
<xsl:call-template name="tid">
<xsl:with-param name="fall_back" select="device[@id=$fall_back]/@fall_back"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>