source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/templates/NSfunctions10.kid @ 2981

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/templates/NSfunctions10.kid@2981
Revision 2981, 6.2 KB checked in by lawrence, 12 years ago (diff)

Fix for templating xhtml within NumSim documents.

Line 
1<!-- This is a bunch of named templates for use in NumSim construction -->
2<?python
3 def et2s(x):
4     #use this to strip namespaces for children within text elements
5     cb=x.tag.find('}')
6     if cb!=-1:x.tag=x.tag[cb+1:]
7     txt=(x.text or '')
8     s='<%s>%s'%(x.tag,txt)
9     for a in x:
10         s+=et2s(a)
11     s+='</%s>%s'%(x.tag,(x.tail or ''))
12     return s
13     ?>
14<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#">
15
16    <span py:def="Text(elem)">
17        <!-- Note that we have to expect the possibility of xhtml in these elements and we won't
18        want the parent attributes, or the namespaces -->
19        ${elem.text or ''}
20        <?python
21        s=''
22        for a in elem:s+=et2s(a)
23        ?>
24        ${XML(s)}
25    </span>
26       
27    <div py:def="Description(elem,nsfix)">
28        <span py:if="elem is not None">
29            <?python
30            related=(elem.findall(nsfix('relatedTo')) or [])
31            content=elem.find(nsfix('contents'))
32            keywords=(elem.findall(nsfix('keywords')) or [])
33            cb=elem.tag.find('}')
34            ?>
35            <span py:if="content is not None">${elem.tag[cb+1:]}: <span py:replace="Text(content)"/></span>
36            <span py:for="k in keywords">${k.text}(${k.find(nsfix('dictionary')).text})</span>
37            <ul py:if="related!=[]">
38                <li py:for="uri in related"><div py:replace="RelatedTo(uri)"/></li>
39            </ul>
40        </span>
41    </div>
42   
43    <div py:def="References(elem,nsfix)">
44        <div py:if="elem is not None" class="RefList">
45            <?python
46                refs=(elem.findall(nsfix('reference')) or [])
47                refList,linkList=[],[]
48                for r in refs:
49                    href=r.attrib.get('{http://www.w3.org/1999/xlink}href')
50                    title=r.attrib.get('{http://www.w3.org/1999/xlink}title')
51                    #note that the attribs are compulsory, although they may be empty, but
52                    #we can't rely on that :-)
53                    l={'href':(href or ''),'title':(title or '')}
54                    if l['href']=='' and l['title']=='': l={}
55                    r.attrib={}
56                    b=('','')
57                    if r.text is not None and l!={}: b=('(',')')
58                    refList.append((r,l,b))
59            ?>
60            References:
61            <ul>
62                <li py:for="r in refList"><span py:replace="Text(r[0])"/>${r[2][0]}<a py:if="r[1]!={}" href="${r[1]['href']}">${r[1]['title']}</a>${r[2][1]}</li>
63            </ul>
64        </div>
65    </div>
66   
67    <div py:def="Parameters(elem,nsfix)">
68        <div py:if="elem is not None">
69            <ul>
70                <li py:for="i in elem.findall(nsfix('NS_RelatedURI'))"><span py:replace="Text(i)"/></li>
71            </ul>
72        </div>
73    </div>
74   
75    <div py:def="RelatedTo(elem,nsfix)">
76        <div py:if="elem is not None">
77            <?python
78            href=elem.attrib.get('{http://www.w3.org/1999/xlink}href')
79            title=elem.attrib.get('{http://www.w3.org/1999/xlink}title')
80            rel=elem.find(nsfix('description'))
81            if rel is not None:
82                s=(rel.text or '')
83            else:
84                #if there is no description, then these must exist
85                r=[i.text for i in elem.findall(nsfix('relationship'))]
86                s=','.join(r)
87            ?>
88            $s <a href="$href">$title</a>
89        </div>
90    </div>
91    <!--
92    <NS_RelatedModel
93        xlink:href="http://www.higem.nerc.ac.uk/"
94        xlink:title="HiGEM">
95    <NS_Relationship>This is the first HiGEM climate run </NS_Relationship>
96    -->
97   
98    <div py:def="Condition(i,nsfix)">
99        <?python
100        ty=i.attrib.get('NS_Type')
101        pe=i.attrib.get('NS_Perturbed')
102        if ty is None: ty=''
103        if pe is None: pe=''
104        ?>
105        <p class="emphatic"> $i.tag $ty $pe </p>
106        <div py:replace="Description(i.find(nsfix('NS_Description')),nsfix)"/>
107        <div py:replace="References(i.find(nsfix('NS_References')),nsfix)"/>
108        <div py:replace="Parameters(i.find(nsfix('NS_ControlledParameters')),nsfix)"/>
109        <div py:replace="RelatedTo(i.find(nsfix('NS_BoundaryDataset')),nsfix)"/>
110       
111    </div>
112   
113    <div py:def="Model(elem,nsfix)" class="Model">
114        <table py:if="elem is not None" cellspacing="0" cellpadding="3" border="0"><tbody>
115            <?python
116            categoryList=[(i.text or '') for i in elem.findall(nsfix('category'))]
117            compTypeList=[(i.text or '') for i in elem.findall(nsfix('componentType'))]
118            descriptions=(elem.findall(nsfix('description')) or [])
119            refs=elem.find(nsfix('references'))
120            related=(elem.findall(nsfix('relatedModel')) or [])
121            resolution=elem.find(nsfix('resolution'))
122            components=(elem.findall(nsfix('component')) or [])
123            ?>
124            <tr><td class="linehead" colspan="3"><span class="headingO">
125                <span py:replace="Text(elem.find(nsfix('name')))"/></span></td></tr>
126            <tr py:if="categoryList!=[]"><td>category:${','.join(categoryList)}</td></tr>
127            <tr py:if="compTypeList!=[]"><td>type:${','.join(compTypeList)}</td></tr>
128            <tr py:for="d in descriptions"><td><div py:replace="Description(d,nsfix)"/></td></tr>
129            <tr py:if="resolution!=None"><td><div py:replace="Description(resolution,nsfix)"/></td></tr>
130            <tr py:for="r in related"><td><div py:replace="RelatedTo(r,nsfix)"/></td></tr>
131            <tr py:if="refs is not None"><td><div py:replace="References(refs,nsfix)"/></td></tr>
132            <tr py:for="cmp in components"><td><div py:replace="Model(cmp,nsfix)"/></td></tr>
133        </tbody></table>
134    </div>
135   
136   
137       
138    <div py:def="simulationContent(xmlh)">
139        <div py:if="xmlh.tree[0].tag=='{http://ndg.nerc.ac.uk/numsim}model'"
140             py:replace="Model(xmlh.tree[0],xmlh._distributens)"/><!--
141        <div py:if="xmlh.tree[0].tag=='{http://ndg.nerc.ac.uk/numsim}experiment'"
142             py:replace="Experiment(xmlh.tree[0],xmlh._distributens)"/>
143        <?python dc=xmlh.tree.findall('{http://purl.org/dc/elements/1.1/dc}*')?>
144        <table py:if="dc is not None"><tr py:for="e in dc">
145            <td>${e.tag}</td><td>${e.text}</td></tr>
146        </table>-->
147    </div>
148
149</html>
Note: See TracBrowser for help on using the repository browser.