dep.xsl 4.3 KB

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