2
|
1 <?xml version="1.0" encoding="utf-8"?>
|
|
2 <xsl:stylesheet version="1.0"
|
|
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
4 xmlns:m="http://implab.org/schemas/data-model.v1.xsd"
|
|
5 xmlns:exsl="http://exslt.org/common"
|
4
|
6 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
|
2
|
7 xmlns:t="http://implab.org/schemas/temp"
|
|
8 >
|
|
9 <!--
|
|
10 This template provides 'module' variable which is the
|
|
11 result of processing imports from packages.
|
|
12
|
|
13 Variable $module is a node set created from the result-tree
|
|
14 which is the result of applying templates in mode=preprocess
|
|
15 -->
|
|
16 <xsl:output method="xml" indent="yes" />
|
4
|
17
|
|
18 <msxsl:script language="JScript" implements-prefix="exsl">
|
|
19 this['node-set'] = function (x) {
|
|
20 return x;
|
|
21 }
|
|
22 </msxsl:script>
|
|
23
|
2
|
24 <xsl:variable name="preprocessResult">
|
|
25 <t:module>
|
|
26 <xsl:call-template name="preprocess" />
|
|
27 </t:module>
|
|
28 </xsl:variable>
|
|
29 <xsl:variable name="module" select="exsl:node-set($preprocessResult)/t:module"/>
|
|
30
|
|
31 <xsl:template name="preprocess">
|
|
32 <xsl:param name="root" select="/" />
|
|
33 <xsl:param name="pending" select="$root/m:package/m:import[@href]" />
|
|
34 <xsl:param name="seen" select="/.." />
|
|
35 <xsl:param name="file" select="''" />
|
|
36 <xsl:param name="primary" select="true()" />
|
|
37
|
|
38 <xsl:if test="not($seen[generate-id() = generate-id($root)])">
|
|
39 <xsl:apply-templates select="$root" mode="preprocess">
|
|
40 <xsl:with-param name="primary" select="$primary" />
|
|
41 <xsl:with-param name="file" select="$file" />
|
|
42 </xsl:apply-templates>
|
|
43 <xsl:if test="$pending">
|
|
44 <xsl:variable name="doc" select="document($pending[1]/@href)" />
|
|
45 <xsl:call-template name="preprocess">
|
|
46 <xsl:with-param name="root" select="$doc" />
|
|
47 <xsl:with-param name="file" select="$pending[1]/@href" />
|
|
48 <xsl:with-param name="pending"
|
|
49 select="$pending[position() > 1] | $doc/m:package/m:import[@href]" />
|
|
50 <xsl:with-param name="seen" select="$root | $seen" />
|
|
51 <xsl:with-param name="primary" select="false()" />
|
|
52 </xsl:call-template>
|
|
53 </xsl:if>
|
|
54 </xsl:if>
|
|
55 </xsl:template>
|
|
56
|
|
57 <xsl:template match="m:package" mode="preprocess">
|
|
58 <xsl:param name="primary" />
|
|
59 <xsl:param name="file" />
|
|
60 <xsl:copy>
|
|
61 <xsl:copy-of select="@*" />
|
|
62 <xsl:if test="$primary">
|
|
63 <xsl:attribute name="primary"><xsl:value-of select="$primary" /></xsl:attribute>
|
|
64 </xsl:if>
|
|
65 <xsl:if test="$file">
|
|
66 <xsl:attribute name="file"><xsl:value-of select="$file" /></xsl:attribute>
|
|
67 </xsl:if>
|
|
68 <xsl:apply-templates mode="preprocess">
|
|
69 <xsl:with-param name="primary" select="$primary" />
|
|
70 <xsl:with-param name="file" select="$file" />
|
|
71 </xsl:apply-templates>
|
|
72 </xsl:copy>
|
|
73 </xsl:template>
|
|
74
|
|
75 <xsl:template match="*|/" mode="preprocess">
|
|
76 <xsl:param name="primary" />
|
|
77 <xsl:param name="file" />
|
|
78 <xsl:copy>
|
|
79 <xsl:copy-of select="@*" />
|
|
80 <xsl:apply-templates mode="preprocess">
|
|
81 <xsl:with-param name="primary" select="$primary" />
|
|
82 <xsl:with-param name="file" select="$file" />
|
|
83 </xsl:apply-templates>
|
|
84 </xsl:copy>
|
|
85 </xsl:template>
|
|
86 </xsl:stylesheet> |