| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
| 3 |
<!-- |
| 4 |
SPDX-License-Identifier: MIT |
| 5 |
|
| 6 |
Copyright The SCons Foundation |
| 7 |
|
| 8 |
xmldepend.xsl - Find files that an XML document refers to/depends on. |
| 9 |
|
| 10 |
This stylesheet can be used to build Makefile dependency lists. |
| 11 |
|
| 12 |
Dependencies are defined as: |
| 13 |
- Files named in <xi:xinclude> elements. These must be traversed to |
| 14 |
find any subdependencies, unless parse attribute is "text". |
| 15 |
- Files named by the fileref attribute of any other element. |
| 16 |
|
| 17 |
Who-to-blame: |
| 18 |
Paul DuBois |
| 19 |
[email protected] |
| 20 |
2005-08-16 |
| 21 |
|
| 22 |
Change history: |
| 23 |
2005-08-16 |
| 24 |
- Version 1.00. |
| 25 |
|
| 26 |
TODO: |
| 27 |
- add params for whether to produce debugging output, etc. |
| 28 |
--> |
| 29 |
|
| 30 |
<xsl:output method="text" indent="no"/> |
| 31 |
|
| 32 |
<!-- BEGIN PARAMETERS --> |
| 33 |
|
| 34 |
<xsl:param name="xmldepend.terminator" select="' '"/> |
| 35 |
|
| 36 |
<!-- END PARAMETERS --> |
| 37 |
|
| 38 |
<!-- BEGIN UTILITY TEMPLATES --> |
| 39 |
|
| 40 |
<!-- |
| 41 |
Given a pathname, return the basename (part after last '/'): |
| 42 |
- If path contains no '/' separators, return entire value |
| 43 |
- If path contains '/' separator, recurse using part after first one |
| 44 |
--> |
| 45 |
|
| 46 |
<xsl:template name="path-basename"> |
| 47 |
<xsl:param name="path"/> |
| 48 |
<xsl:choose> |
| 49 |
<xsl:when test="not(contains($path,'/'))"> |
| 50 |
<xsl:value-of select="$path"/> |
| 51 |
</xsl:when> |
| 52 |
<xsl:otherwise> |
| 53 |
<xsl:call-template name="path-basename"> |
| 54 |
<xsl:with-param name="path" select="substring-after($path,'/')"/> |
| 55 |
</xsl:call-template> |
| 56 |
</xsl:otherwise> |
| 57 |
</xsl:choose> |
| 58 |
</xsl:template> |
| 59 |
|
| 60 |
<!-- |
| 61 |
Given a pathname, return the dirname (part up through last '/'): |
| 62 |
- If path contains no '/' separators, return empty string |
| 63 |
- If path contains '/' separator, return part up through last one |
| 64 |
(which is the same as the part before the basename) |
| 65 |
--> |
| 66 |
|
| 67 |
<xsl:template name="path-dirname"> |
| 68 |
<xsl:param name="path"/> |
| 69 |
<xsl:choose> |
| 70 |
<xsl:when test="not(contains($path,'/'))"> |
| 71 |
<!-- return nothing --> |
| 72 |
</xsl:when> |
| 73 |
<xsl:otherwise> |
| 74 |
<xsl:variable name="basename"> |
| 75 |
<xsl:call-template name="path-basename"> |
| 76 |
<xsl:with-param name="path" select="$path"/> |
| 77 |
</xsl:call-template> |
| 78 |
</xsl:variable> |
| 79 |
<xsl:value-of select="substring( $path,1,string-length($path) - string-length($basename) )"/> |
| 80 |
</xsl:otherwise> |
| 81 |
</xsl:choose> |
| 82 |
</xsl:template> |
| 83 |
|
| 84 |
<!-- END UTILITY TEMPLATES --> |
| 85 |
|
| 86 |
<!-- |
| 87 |
Find XInclude directives, spit out the href value that names |
| 88 |
the included file, and process the file recursively if it's |
| 89 |
an XML file. |
| 90 |
--> |
| 91 |
|
| 92 |
<xsl:template match="xi:include" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 93 |
<xsl:param name="curdir"/> |
| 94 |
|
| 95 |
<xsl:variable name="href-dir"> |
| 96 |
<xsl:call-template name="path-dirname"> |
| 97 |
<xsl:with-param name="path" select="@href"/> |
| 98 |
</xsl:call-template> |
| 99 |
</xsl:variable> |
| 100 |
|
| 101 |
<!-- |
| 102 |
Display pathname of included file. It should be prefixed by |
| 103 |
the directory of the referring file unless the included file |
| 104 |
is an absolute pathname. |
| 105 |
--> |
| 106 |
|
| 107 |
<xsl:if test="not(starts-with(@href,'/'))"> |
| 108 |
<xsl:value-of select="$curdir"/> |
| 109 |
</xsl:if> |
| 110 |
<xsl:value-of select="@href"/> |
| 111 |
<xsl:value-of select="$xmldepend.terminator"/> |
| 112 |
|
| 113 |
<!-- |
| 114 |
Process included file (unless parse="text"). |
| 115 |
Pass directory of included file while processing it |
| 116 |
so that relative pathnames referenced in the document |
| 117 |
can be resolved properly. |
| 118 |
--> |
| 119 |
|
| 120 |
<xsl:if test="not(@parse = 'text')"> |
| 121 |
<xsl:for-each select="document(@href)"> |
| 122 |
<xsl:apply-templates> |
| 123 |
<xsl:with-param name="curdir"> |
| 124 |
<xsl:if test="not(starts-with(@href,'/'))"> |
| 125 |
<xsl:value-of select="$curdir"/> |
| 126 |
</xsl:if> |
| 127 |
<xsl:value-of select="$href-dir"/> |
| 128 |
</xsl:with-param> |
| 129 |
</xsl:apply-templates> |
| 130 |
</xsl:for-each> |
| 131 |
</xsl:if> |
| 132 |
</xsl:template> |
| 133 |
|
| 134 |
<!-- |
| 135 |
Several elements have a fileref attribute. Spit out the file named |
| 136 |
by any of them. Resolve the filename relative to the directory of |
| 137 |
the referencing file unless the name is an absolute pathname. |
| 138 |
--> |
| 139 |
|
| 140 |
<xsl:template match="*[@fileref]"> |
| 141 |
<xsl:param name="curdir"/> |
| 142 |
|
| 143 |
<xsl:if test="not(starts-with(@fileref,'/'))"> |
| 144 |
<xsl:value-of select="$curdir"/> |
| 145 |
</xsl:if> |
| 146 |
<xsl:value-of select="@fileref"/> |
| 147 |
<xsl:value-of select="$xmldepend.terminator"/> |
| 148 |
</xsl:template> |
| 149 |
|
| 150 |
<!-- Identity transform, but keep track of current document directory --> |
| 151 |
|
| 152 |
<xsl:template match="*"> |
| 153 |
<xsl:param name="curdir"/> |
| 154 |
<xsl:apply-templates select="*"> |
| 155 |
<xsl:with-param name="curdir" select="$curdir"/> |
| 156 |
</xsl:apply-templates> |
| 157 |
</xsl:template> |
| 158 |
|
| 159 |
</xsl:stylesheet> |