comparison xslt/preprocess.xsl @ 2:035de8b7b18e

Temporary commit, refactoring, added readme
author cin
date Sun, 25 Feb 2018 17:12:33 +0300
parents
children d240adc2ac70
comparison
equal deleted inserted replaced
1:7f803979305f 2:035de8b7b18e
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"
6 xmlns:t="http://implab.org/schemas/temp"
7 >
8 <!--
9 This template provides 'module' variable which is the
10 result of processing imports from packages.
11
12 Variable $module is a node set created from the result-tree
13 which is the result of applying templates in mode=preprocess
14 -->
15 <xsl:output method="xml" indent="yes" />
16 <xsl:variable name="preprocessResult">
17 <t:module>
18 <xsl:call-template name="preprocess" />
19 </t:module>
20 </xsl:variable>
21 <xsl:variable name="module" select="exsl:node-set($preprocessResult)/t:module"/>
22
23 <xsl:template name="preprocess">
24 <xsl:param name="root" select="/" />
25 <xsl:param name="pending" select="$root/m:package/m:import[@href]" />
26 <xsl:param name="seen" select="/.." />
27 <xsl:param name="file" select="''" />
28 <xsl:param name="primary" select="true()" />
29
30 <xsl:if test="not($seen[generate-id() = generate-id($root)])">
31 <xsl:apply-templates select="$root" mode="preprocess">
32 <xsl:with-param name="primary" select="$primary" />
33 <xsl:with-param name="file" select="$file" />
34 </xsl:apply-templates>
35 <xsl:if test="$pending">
36 <xsl:variable name="doc" select="document($pending[1]/@href)" />
37 <xsl:call-template name="preprocess">
38 <xsl:with-param name="root" select="$doc" />
39 <xsl:with-param name="file" select="$pending[1]/@href" />
40 <xsl:with-param name="pending"
41 select="$pending[position() > 1] | $doc/m:package/m:import[@href]" />
42 <xsl:with-param name="seen" select="$root | $seen" />
43 <xsl:with-param name="primary" select="false()" />
44 </xsl:call-template>
45 </xsl:if>
46 </xsl:if>
47 </xsl:template>
48
49 <xsl:template match="m:package" mode="preprocess">
50 <xsl:param name="primary" />
51 <xsl:param name="file" />
52 <xsl:copy>
53 <xsl:copy-of select="@*" />
54 <xsl:if test="$primary">
55 <xsl:attribute name="primary"><xsl:value-of select="$primary" /></xsl:attribute>
56 </xsl:if>
57 <xsl:if test="$file">
58 <xsl:attribute name="file"><xsl:value-of select="$file" /></xsl:attribute>
59 </xsl:if>
60 <xsl:apply-templates mode="preprocess">
61 <xsl:with-param name="primary" select="$primary" />
62 <xsl:with-param name="file" select="$file" />
63 </xsl:apply-templates>
64 </xsl:copy>
65 </xsl:template>
66
67 <xsl:template match="*|/" mode="preprocess">
68 <xsl:param name="primary" />
69 <xsl:param name="file" />
70 <xsl:copy>
71 <xsl:copy-of select="@*" />
72 <xsl:apply-templates mode="preprocess">
73 <xsl:with-param name="primary" select="$primary" />
74 <xsl:with-param name="file" select="$file" />
75 </xsl:apply-templates>
76 </xsl:copy>
77 </xsl:template>
78 </xsl:stylesheet>