File: cmdidx.xsl

package info (click to toggle)
fityk 0.4.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,472 kB
  • ctags: 2,617
  • sloc: cpp: 19,705; sh: 5,965; xml: 2,325; yacc: 356; makefile: 183; lex: 178
file content (104 lines) | stat: -rw-r--r-- 3,224 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?xml version="1.0"?>
<!-- XSLT stylesheet for generating command and option indices (DocBook -> DocBook) -->
<!-- (C) Marcin Wojdyr  -->
<!-- $Id: cmdidx.xsl,v 1.2 2003/12/23 16:43:05 wojdyr Exp $ -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" 
          doctype-public="-//OASIS//DTD DocBook XML V4.2//EN" 
          doctype-system="http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"/>

  <xsl:template match="/">
    <xsl:copy/>
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="*">
    <xsl:copy>
      <xsl:for-each select="@*">
        <xsl:copy/>
      </xsl:for-each>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="comment()|processing-instruction()">
    <xsl:copy/>
  </xsl:template>

  <xsl:variable name="command_def" select="//cmdsynopsis/command"/>
  <xsl:variable name="option_def" select="//parameter[@class='option'][local-name(..)!='link']"/>

  <!-- adding id for commands and options in text -->
  <xsl:template match="cmdsynopsis/command|parameter[@class='option']">
    <xsl:copy>
      <xsl:attribute name="id">
        <xsl:value-of select="generate-id()"/>
      </xsl:attribute>
      <xsl:for-each select="@*">
        <xsl:copy/>
      </xsl:for-each>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <!-- option index -->
  <xsl:template match="para[@role='optidx']">
    <simplelist>
      <xsl:for-each select="$option_def">
        <xsl:sort select="."/>
	<xsl:variable name="this_opt" select="$option_def[.=current()]"/>
        <xsl:if test="count(.|$this_opt[1]) = 1"> 
          <xsl:apply-templates select="." mode="o_idx"/>
	</xsl:if>
      </xsl:for-each>
    </simplelist>
  </xsl:template>

  <xsl:template match="*" mode="o_idx">
    <member>
      <xsl:element name="link">
        <xsl:attribute name="linkend">
          <xsl:value-of select="generate-id()"/>
        </xsl:attribute>
        <xsl:value-of select="."/> 
      </xsl:element>
      <xsl:variable name="cmd-try" select="../../para/cmdsynopsis/command"/>
      <xsl:choose>
       <xsl:when test="$cmd-try">
        (<xsl:value-of select="substring($cmd-try, 1, 1)"/>.set)
       </xsl:when>
       <xsl:otherwise>
        <xsl:variable name="cmd" 
			select="../../../section/para/cmdsynopsis/command"/>
        (<xsl:value-of select="substring($cmd, 1, 1)"/>.set)
       </xsl:otherwise>
      </xsl:choose>
    </member>
  </xsl:template>

  <!-- command index -->
  <xsl:template match="para[@role='cmdidx']">
    <simplelist>
      <xsl:for-each select="$command_def">
        <xsl:sort select="."/>
	<xsl:variable name="this_cmd" select="$command_def[.=current()]"/>
        <xsl:if test="count(.|$this_cmd[1]) = 1">
          <xsl:apply-templates select="." mode="c_idx"/>
	</xsl:if>
      </xsl:for-each>
    </simplelist>
  </xsl:template>

  <xsl:template match="*" mode="c_idx">
    <member>
      <xsl:element name="link">
        <xsl:attribute name="linkend">
          <xsl:value-of select="generate-id()"/>
        </xsl:attribute>
        <xsl:value-of select="."/> 
      </xsl:element>
    </member>
  </xsl:template>

</xsl:stylesheet>