dump-commands.xsl 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 = 'root'">
  46. <xsl:text>&#xA;</xsl:text>
  47. <xsl:text># Run this as root</xsl:text>
  48. <xsl:apply-templates select="userinput"/>
  49. <xsl:text># End root commands</xsl:text>
  50. <xsl:text>&#xA;</xsl:text>
  51. </xsl:when>
  52. <xsl:otherwise>
  53. <xsl:apply-templates select="userinput"/>
  54. </xsl:otherwise>
  55. </xsl:choose>
  56. </xsl:if>
  57. </xsl:template>
  58. <xsl:template match="userinput">
  59. <xsl:text>&#xA;</xsl:text>
  60. <xsl:if test=".//replaceable">
  61. <xsl:text># This block must be edited to suit your needs.</xsl:text>
  62. </xsl:if>
  63. <xsl:text>&#xA;</xsl:text>
  64. <xsl:apply-templates/>
  65. <xsl:text>&#xA;</xsl:text>
  66. <xsl:if test=".//replaceable">
  67. <xsl:text># End of editable block.</xsl:text>
  68. </xsl:if>
  69. <xsl:text>&#xA;</xsl:text>
  70. </xsl:template>
  71. <xsl:template match="replaceable">
  72. <xsl:text>**EDITME</xsl:text>
  73. <xsl:apply-templates/>
  74. <xsl:text>EDITME**</xsl:text>
  75. </xsl:template>
  76. </xsl:stylesheet>