OnyxExportOntology: mapVariablesToOnyxOntology.xslt

File mapVariablesToOnyxOntology.xslt, 2.1 KB (added by jason.selby, 13 years ago)

maps the variables xml file to the onyx schema

Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
3 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
4 <xsl:template match="*">
5 <xsl:apply-templates select="variables"/>
6 </xsl:template>
7 <xsl:template match="/variables">
8 <xsl:element name="source">
9 <xsl:element name="name">briccs</xsl:element>
10 <!-- only interested in variable elements with a child of categories -->
11 <xsl:apply-templates select="variable[categories]"/>
12 </xsl:element>
13 </xsl:template>
14 <!-- only want one stage element and subsequent section etc so apply only when it's the first in the list rather than all of them -->
15 <xsl:template match="variable[categories][position()=1]">
16 <xsl:element name="stage">
17 <xsl:element name="name">
18 <xsl:value-of select="attributes/attribute[@name='stage']"/>
19 </xsl:element>
20 <xsl:element name="section">
21 <xsl:element name="name">
22 <xsl:value-of select="attributes/attribute[@name='section']"/>
23 </xsl:element>
24 <!-- to get the depth right we now need to go up the tree and get all the variables with categories and loop thru them -->
25 <xsl:for-each select="//variable[categories]">
26 <xsl:element name="question">
27 <xsl:element name="name">
28 <xsl:value-of select="@name"/>
29 </xsl:element>
30 <xsl:element name="label">
31 <xsl:value-of select="attributes/attribute[@name='label']"/>
32 </xsl:element>
33 <!-- now get all the categories below where we are -->
34 <xsl:apply-templates select="categories"/>
35 </xsl:element>
36 </xsl:for-each>
37 </xsl:element>
38 </xsl:element>
39 </xsl:template>
40 <xsl:template match="categories">
41 <xsl:element name="variable">
42 <xsl:element name="name">
43 <xsl:value-of select="../attributes/attribute[@name='questionName']"/>
44 </xsl:element>
45 <xsl:element name="type">
46 <xsl:value-of select="../@valueType"/>
47 </xsl:element>
48 <xsl:apply-templates/>
49 </xsl:element>
50 </xsl:template>
51</xsl:stylesheet>