dump-commands.xsl 2.9 KB

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