1 | <?xml version="1.0"?> |
---|
2 | <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
---|
3 | xmlns:my="myFunctions"> |
---|
4 | |
---|
5 | <!-- |
---|
6 | <purpose>functions for SMC</purpose> |
---|
7 | <history> |
---|
8 | <change on="2011-10-28" type="created" by="vr">based on cmd_functions.xsl</change> |
---|
9 | </history> |
---|
10 | --> |
---|
11 | |
---|
12 | <!-- |
---|
13 | @param profiles - list of <profileDescription> |
---|
14 | --> |
---|
15 | <xsl:function name="my:profiles2termsets" > |
---|
16 | <xsl:param name="profiles"/> |
---|
17 | |
---|
18 | <Termsets count="{count($profiles)}"> |
---|
19 | <xsl:for-each select="$profiles" > |
---|
20 | <xsl:variable name="profile_id" select="id"></xsl:variable> |
---|
21 | <Termset name="{name}" id="{$profile_id}" type="CMD_Profile"> |
---|
22 | |
---|
23 | <!-- flattening the structure! --> |
---|
24 | <xsl:for-each select=".//CMD_Component|.//CMD_Element" > |
---|
25 | <xsl:variable name="context" select="my:context(.)" /> |
---|
26 | |
---|
27 | <xsl:variable name="type" select="name()" /> |
---|
28 | <xsl:variable name="id" > |
---|
29 | <xsl:choose> |
---|
30 | <xsl:when test="@ComponentId"> |
---|
31 | <xsl:value-of select="@ComponentId" /> |
---|
32 | </xsl:when> |
---|
33 | <!-- top component = profile --> |
---|
34 | <xsl:when test="not(exists(ancestor::CMD_Component))"> |
---|
35 | <xsl:value-of select="$profile_id" /> |
---|
36 | </xsl:when> |
---|
37 | <xsl:otherwise> |
---|
38 | <xsl:value-of select="ancestor::CMD_Component[@ComponentId][1]/@ComponentId" /><xsl:text>#</xsl:text> |
---|
39 | <xsl:for-each select="ancestor::CMD_Component[not(descendant-or-self::CMD_Component[@ComponentId])]" > |
---|
40 | <xsl:value-of select="@name" />.</xsl:for-each><xsl:value-of select="@name" /> |
---|
41 | </xsl:otherwise> |
---|
42 | </xsl:choose> |
---|
43 | </xsl:variable> |
---|
44 | <Term type="{$type}" name="{@name}" datcat="{@ConceptLink}" id="{$id}" elem="{@name}" |
---|
45 | parent="{ancestor::CMD_Component[1]/@name}" path="{$context}" |
---|
46 | > |
---|
47 | <!-- <xsl:copy-of select="." /> --> |
---|
48 | </Term> |
---|
49 | </xsl:for-each> |
---|
50 | </Termset> |
---|
51 | </xsl:for-each> |
---|
52 | </Termsets> |
---|
53 | </xsl:function> |
---|
54 | |
---|
55 | <!-- |
---|
56 | <xsl:function name="my:profile2termset" > |
---|
57 | <xsl:param name="term"/> |
---|
58 | |
---|
59 | <xsl:variable name="profile" select="my:profile($term,true())" /> |
---|
60 | <xsl:copy-of select="my:profiles2termsets($profile)" /> |
---|
61 | |
---|
62 | </xsl:function> |
---|
63 | |
---|
64 | <xsl:function name="my:profile" > |
---|
65 | <xsl:param name="term"/> |
---|
66 | <xsl:param name="resolve" /> <!-\- true|false-\-> |
---|
67 | |
---|
68 | <!-\- <xsl:message>cmdprofiles_uri: <xsl:value-of select="$cmdprofiles_uri" /></xsl:message> -\-> |
---|
69 | |
---|
70 | <xsl:variable name="profile" select="$cmd_profiles//profileDescription[name=$term or $term='all']" /> |
---|
71 | |
---|
72 | <xsl:choose> |
---|
73 | <xsl:when test="$resolve=true()"> |
---|
74 | <xsl:apply-templates select="$profile" mode="include" /> |
---|
75 | </xsl:when> |
---|
76 | <xsl:otherwise> |
---|
77 | <xsl:copy-of select="$profile" /> |
---|
78 | </xsl:otherwise> |
---|
79 | </xsl:choose> |
---|
80 | |
---|
81 | |
---|
82 | </xsl:function>--> |
---|
83 | |
---|
84 | <!-- constructs a dot-path from ancestor-CMD_component-elements --> |
---|
85 | <xsl:function name="my:context" > |
---|
86 | <xsl:param name="child" /> |
---|
87 | <xsl:variable name="collect" > |
---|
88 | <xsl:for-each select="$child/ancestor::CMD_Component|$child/ancestor::Term" > |
---|
89 | <xsl:value-of select="@name" />.</xsl:for-each><xsl:value-of select="$child/@name" /> |
---|
90 | </xsl:variable> |
---|
91 | <xsl:value-of select="$collect" /> |
---|
92 | </xsl:function> |
---|
93 | |
---|
94 | |
---|
95 | </xsl:stylesheet> |
---|