dump-commands.xsl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:exsl="http://exslt.org/common"
  4. extension-element-prefixes="exsl"
  5. version="1.0">
  6. <!-- XSLT stylesheet to extract commands from [B,H]LFS books. -->
  7. <xsl:variable name="newline">
  8. <xsl:text>&#xA;</xsl:text>
  9. </xsl:variable>
  10. <xsl:template match="/">
  11. <xsl:apply-templates select="//sect1"/>
  12. </xsl:template>
  13. <xsl:template match="sect1">
  14. <!-- The dirs names -->
  15. <xsl:variable name="pi-dir" select="../processing-instruction('dbhtml')"/>
  16. <xsl:variable name="pi-dir-value" select="substring-after($pi-dir,'dir=')"/>
  17. <xsl:variable name="quote-dir" select="substring($pi-dir-value,1,1)"/>
  18. <xsl:variable name="dirname" select="substring-before(substring($pi-dir-value,2),$quote-dir)"/>
  19. <!-- The file names -->
  20. <xsl:variable name="pi-file" select="processing-instruction('dbhtml')"/>
  21. <xsl:variable name="pi-file-value" select="substring-after($pi-file,'filename=')"/>
  22. <xsl:variable name="filename" select="substring-before(substring($pi-file-value,2),'.html')"/>
  23. <!-- The build order -->
  24. <xsl:variable name="position" select="position()"/>
  25. <xsl:variable name="order">
  26. <xsl:choose>
  27. <xsl:when test="string-length($position) = 1">
  28. <xsl:text>00</xsl:text>
  29. <xsl:value-of select="$position"/>
  30. </xsl:when>
  31. <xsl:when test="string-length($position) = 2">
  32. <xsl:text>0</xsl:text>
  33. <xsl:value-of select="$position"/>
  34. </xsl:when>
  35. <xsl:otherwise>
  36. <xsl:value-of select="$position"/>
  37. </xsl:otherwise>
  38. </xsl:choose>
  39. </xsl:variable>
  40. <!-- Creating dirs and files -->
  41. <exsl:document href="{$dirname}/{$order}-{$filename}" method="text">
  42. <xsl:apply-templates select=".//screen"/>
  43. </exsl:document>
  44. </xsl:template>
  45. <xsl:template match="screen">
  46. <xsl:if test="child::* = userinput">
  47. <xsl:choose>
  48. <xsl:when test="@role = 'root'">
  49. <xsl:text># Run this as root</xsl:text>
  50. <xsl:value-of select="$newline"/>
  51. <xsl:apply-templates select="userinput"/>
  52. <xsl:text># End root commands</xsl:text>
  53. <xsl:value-of select="$newline"/>
  54. </xsl:when>
  55. <xsl:otherwise>
  56. <xsl:apply-templates select="userinput"/>
  57. </xsl:otherwise>
  58. </xsl:choose>
  59. <xsl:value-of select="$newline"/>
  60. </xsl:if>
  61. </xsl:template>
  62. <xsl:template match="userinput">
  63. <xsl:if test=".//replaceable">
  64. <xsl:text># This block must be edited to suit your needs.</xsl:text>
  65. <xsl:value-of select="$newline"/>
  66. </xsl:if>
  67. <xsl:apply-templates/>
  68. <xsl:value-of select="$newline"/>
  69. <xsl:if test=".//replaceable">
  70. <xsl:text># End of editable block.</xsl:text>
  71. <xsl:value-of select="$newline"/>
  72. </xsl:if>
  73. </xsl:template>
  74. <xsl:template match="replaceable">
  75. <xsl:text>**EDITME</xsl:text>
  76. <xsl:apply-templates/>
  77. <xsl:text>EDITME**</xsl:text>
  78. </xsl:template>
  79. </xsl:stylesheet>