docbook: fix rm'ed files mentioned in .d build error
[sip-router] / docbook / dep.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                                 version='1.0' xmlns:xi="http://www.w3.org/2001/XInclude">
4         <xsl:param name="output"/>
5
6         <!-- Write the output into a plaintext file which will be later included
7                  into the Makefile -->
8         <xsl:template match="/">
9                 <xsl:document href="{$output}" method="text" indent="no" 
10                                           omit-xml-declaration="yes">
11                         <xsl:value-of select="concat($output, ':$(wildcard  ')"/>
12                         <xsl:apply-templates mode="subroot"/>
13                         <xsl:text>)&#xA;</xsl:text>
14                 </xsl:document>
15         </xsl:template>
16         
17         <!-- This template extract the name of the directory from a full pathname,
18              in other words it returns everything but the name of the file -->
19         <xsl:template name="dirname">
20                 <xsl:param name="filename"/>
21                 <xsl:if test="contains($filename, '/')">
22                         <xsl:value-of 
23                                 select="concat(substring-before($filename, '/'), '/')"/>
24                         <xsl:call-template name="dirname">
25                                 <xsl:with-param name="filename" 
26                                                                 select="substring-after($filename, '/')"/>
27                         </xsl:call-template>
28                 </xsl:if>
29         </xsl:template>
30
31         <!-- This template is used to add a directory preefix to a filename. The
32              prefix is only added if the filename is not absolute (i.e. it does
33              not start with a / and if the prefix is not an empty string -->
34         <xsl:template name="addprefix">
35                 <xsl:param name="prefix"/>
36                 <xsl:param name="filename"/>
37                 <xsl:if test="(string-length($prefix) > 0) and not(starts-with($filename, '/'))">
38                         <xsl:value-of select="$prefix"/>
39                 </xsl:if>
40                 <xsl:value-of select="$filename"/>
41         </xsl:template>
42         
43         <!-- This template processes xi:include directives that include other XML
44              documents. First the template outputs the name of the file being
45              included and then the template traverses the included file
46              recursively, searching fro other dependencies in that file.  The
47              template passes the parameter prefix to other templates with its
48              value set to the directory name of the file being included. This
49              ensures that paths to all dependencies are relative to the main
50              file. -->
51         <xsl:template match='xi:include' mode="subroot">
52                 <xsl:param name="prefix"/>
53
54                 <!-- Add the prefix to the name of the file being included and store
55                      the result in variable fullpath -->
56                 <xsl:variable name="fullpath">
57                         <xsl:call-template name="addprefix">
58                                 <xsl:with-param name="prefix" select="$prefix"/>
59                                 <xsl:with-param name="filename" select="@href"/>
60                         </xsl:call-template>
61                 </xsl:variable>
62
63                 <!-- First of all, output the name of the file being included, with
64                      proper prefix so that the resulting dependency is relative to the
65                      top-most file being processed, not the file we are are processing
66                      in this step. -->
67                 <xsl:value-of select="concat($fullpath, ' ')"/>
68
69                 <!-- Traverse the file being included and search for more depencencies
70                      in that file and other files included from there. -->
71                 <xsl:apply-templates select="document(@href)" mode="subroot">
72                         <!-- Extract the directory name from $fullpath and set it as a new
73                              value of the prefix parameter before calling other templates.
74                         -->
75                         <xsl:with-param name="prefix">
76                                 <xsl:call-template name="dirname">
77                                         <xsl:with-param name="filename" select="$fullpath"/>
78                                 </xsl:call-template>
79                         </xsl:with-param>
80
81                         <!-- Process the included file recursively -->
82                 </xsl:apply-templates>
83         </xsl:template>
84         
85         <!-- This template processes files included with xi:include that are not
86              XML files, such files will only be output as dependencies and will be
87              not traversed recursively. -->
88         <xsl:template match='xi:include[@parse="text"]' mode="subroot">
89                 <xsl:param name="prefix"/>
90                 <xsl:call-template name="addprefix">
91                         <xsl:with-param name="prefix" select="$prefix"/>
92                         <xsl:with-param name="filename" select="@href"/>
93                 </xsl:call-template>
94                 <xsl:text> </xsl:text>
95         </xsl:template>
96         
97         <!-- This template processes mediaobjects (such as images) included in
98              docbook. -->
99         <xsl:template match="graphic|imagedata|inlinemediaobject|textdata" 
100                                   mode="subroot">
101                 <xsl:param name="prefix"/>
102                 <xsl:call-template name="addprefix">
103                         <xsl:with-param name="prefix" select="$prefix"/>
104                         <xsl:with-param name="filename" select="@fileref"/>
105                 </xsl:call-template>
106                 <xsl:text> </xsl:text>
107         </xsl:template>
108         
109         <!-- Supress all other output -->
110         <xsl:template match="text()|@*" mode="subroot"/>
111 </xsl:stylesheet>