Debian Codegraph @

chado-xml/xsl/chado-expand-macros.xsl

raw symbols SCIP
1 <?xml version="1.0" encoding="utf-8"?>
2
3 <!-- AUTHOR: Chris Mungall cjm at fruitfly dot org -->
4
5 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6 version="1.0">
7
8 <xsl:output indent="yes" method="xml"/>
9
10 <!-- index everything with an ID attribute -->
11 <xsl:key name="k-macro" match="//*" use="@id"/>
12
13 <!-- match everything -->
14 <xsl:template match="/ | @* | node()">
15 <xsl:choose>
16 <!-- replace terminal xxx_id elements with expanded macro -->
17 <xsl:when test="contains(name(.),'_id') and not(*)">
18 <xsl:if test="not(key('k-macro',.))">
19 <xsl:message>No such ID: <xsl:value-of select="."/></xsl:message>
20 </xsl:if>
21 <!-- fetch expansion term from ID index -->
22 <xsl:copy>
23 <xsl:variable name="macro" select="key('k-macro',.)"/>
24 <!-- recursively process macros (removing id attr) -->
25 <xsl:for-each select="$macro">
26 <xsl:copy>
27 <xsl:apply-templates select="$macro/*"/>
28 </xsl:copy>
29 </xsl:for-each>
30 </xsl:copy>
31 </xsl:when>
32 <xsl:when test="count(@id)">
33 <!-- remove existing macros (a macro is anything with id attr) -->
34 </xsl:when>
35 <xsl:otherwise>
36 <!-- recursively apply this same template again -->
37 <xsl:copy>
38 <xsl:apply-templates select="@* | node()" />
39 </xsl:copy>
40 </xsl:otherwise>
41 </xsl:choose>
42 </xsl:template>
43
44 </xsl:stylesheet>