| 263 | |
| 264 | '''Jason's 'bash' at a stylesheet''' |
| 265 | |
| 266 | I've been working on a stylesheet to take the variables.xml onyx etract and make it into Jeff's suggested ontology schema format so here it is :- |
| 267 | |
| 268 | <?xml version="1.0" encoding="UTF-8"?> |
| 269 | <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"> |
| 270 | <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> |
| 271 | <xsl:template match="*"> |
| 272 | <xsl:apply-templates select="variables"/> |
| 273 | </xsl:template> |
| 274 | <xsl:template match="/variables"> |
| 275 | <xsl:element name="source"> |
| 276 | <xsl:element name="name">briccs</xsl:element> |
| 277 | <!-- only interested in variable elements with a child of categories --> |
| 278 | <xsl:apply-templates select="variable[categories]"/> |
| 279 | </xsl:element> |
| 280 | </xsl:template> |
| 281 | <!-- 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 --> |
| 282 | <xsl:template match="variable[categories][position()=1]"> |
| 283 | <xsl:element name="stage"> |
| 284 | <xsl:element name="name"> |
| 285 | <xsl:value-of select="attributes/attribute[@name='stage']"/> |
| 286 | </xsl:element> |
| 287 | <xsl:element name="section"> |
| 288 | <xsl:element name="name"> |
| 289 | <xsl:value-of select="attributes/attribute[@name='section']"/> |
| 290 | </xsl:element> |
| 291 | <!-- to get the depth right we now need to go up the tree and get all the variables with categories and loop thru them --> |
| 292 | <xsl:for-each select="//variable[categories]"> |
| 293 | <xsl:element name="question"> |
| 294 | <xsl:element name="name"> |
| 295 | <xsl:value-of select="@name"/> |
| 296 | </xsl:element> |
| 297 | <xsl:element name="label"> |
| 298 | <xsl:value-of select="attributes/attribute[@name='label']"/> |
| 299 | </xsl:element> |
| 300 | <!-- now get all the categories below where we are --> |
| 301 | <xsl:apply-templates select="categories"/> |
| 302 | </xsl:element> |
| 303 | </xsl:for-each> |
| 304 | </xsl:element> |
| 305 | </xsl:element> |
| 306 | </xsl:template> |
| 307 | <xsl:template match="categories"> |
| 308 | <xsl:element name="variable"> |
| 309 | <xsl:element name="name"> |
| 310 | <xsl:value-of select="../attributes/attribute[@name='questionName']"/> |
| 311 | </xsl:element> |
| 312 | <xsl:element name="type"> |
| 313 | <xsl:value-of select="../@valueType"/> |
| 314 | </xsl:element> |
| 315 | <xsl:apply-templates/> |
| 316 | </xsl:element> |
| 317 | </xsl:template> |
| 318 | </xsl:stylesheet> |
| 319 | |
| 320 | Seems to work quite well but needs more effort around the variable/variable bit below question as I'm not entirely sure where we are sourceing this data from. I've attached the file as well for easier editing etc. |
| 321 | |