source: BLFS/xsl/process-prompt.xsl@ 83cfe91

trunk
Last change on this file since 83cfe91 was a6c57de, checked in by Pierre Labastie <pierre.labastie@…>, 15 months ago

Process <prompt> tags in mit-kerberos

when we have a command followed by prompts:
command
<prompt>command:</prompt> instr
...
we want to transform to:
command << PROMPT_EOF
instr
...
quit
PROMPT_EOF.
This patch implements this. The problem is that the <prompt>
tags may occur in several consecutive <screen> ones. So we create
a fragment tree and process it recursively.

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[a6c57de]1<?xml version="1.0" encoding="ISO-8859-1"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 version="1.0">
4
5 <xsl:template name="process-prompt">
6 <xsl:param name="instructions"/>
7 <xsl:param name="root-seen"/>
8 <xsl:param name="prompt-seen"/>
9
10<!-- Isolate the current instruction -->
11 <xsl:variable name="current-instr" select="$instructions[1]"/>
12
13 <xsl:choose>
14<!--============================================================-->
15<!-- First, if we have an empty tree, close everything and exit -->
16 <xsl:when test="not($current-instr)">
17 <xsl:if test="$prompt-seen">
18 <xsl:call-template name="end-prompt"/>
19 </xsl:if>
20 <xsl:if test="$root-seen">
21 <xsl:call-template name="end-root"/>
22 </xsl:if>
23 </xsl:when><!-- end empty tree -->
24<!--============================================================-->
25 <xsl:when test="$current-instr[@role='root']">
26 <xsl:choose>
27 <xsl:when test="$current-instr//prompt">
28 <xsl:if test="not($root-seen)">
29 <xsl:call-template name="begin-root"/>
30 </xsl:if>
31 <xsl:text>&#xA;</xsl:text>
32 <xsl:if test="not($prompt-seen)">
33 <xsl:copy-of
34 select="substring-before($current-instr//text()[1],'&#xA;')"/>
35 <xsl:text> &lt;&lt; PROMPT_EOF
36</xsl:text>
37 </xsl:if>
38 <xsl:apply-templates
39 select="$current-instr/userinput/node()[position()>1]"/>
40 <xsl:call-template name="process-prompt">
41 <xsl:with-param
42 name="instructions"
43 select="$instructions[position()>1]"/>
44 <xsl:with-param name="root-seen" select="boolean(1)"/>
45 <xsl:with-param name="prompt-seen" select="boolean(1)"/>
46 </xsl:call-template>
47 </xsl:when><!-- end prompt as root -->
48<!--____________________________________________________________ -->
49 <xsl:otherwise><!-- we have no prompt -->
50 <xsl:if test="$prompt-seen">
51 <xsl:text>
52quit
53PROMPT_EOF</xsl:text>
54 </xsl:if>
55 <xsl:apply-templates
56 select="$current-instr"
57 mode="config"/>
58 <!-- the above will call "end-root" if the next screen
59 sibling is not role="root". We need to pass root-seen=false
60 in this case. Otherwise, we need to pass root-seen=true.
61 So create a variable -->
62 <xsl:variable name="rs"
63 select="$instructions[2][@role='root']"/>
64 <xsl:call-template name="process-prompt">
65 <xsl:with-param
66 name="instructions"
67 select="$instructions[position()>1]"/>
68 <xsl:with-param name="root-seen" select="boolean($rs)"/>
69 <xsl:with-param name="prompt-seen" select="boolean(0)"/>
70 </xsl:call-template>
71 </xsl:otherwise><!-- end no prompt -->
72<!--____________________________________________________________ -->
73 </xsl:choose>
74 </xsl:when><!-- role="root" -->
75<!--============================================================-->
76 <xsl:otherwise><!-- no role -->
77 <xsl:if test="$prompt-seen">
78 <xsl:text>
79quit
80PROMPT_EOF</xsl:text>
81 </xsl:if>
82 <xsl:if test="$root-seen">
83 <xsl:call-template name="end-root"/>
84 </xsl:if>
85 <xsl:apply-templates select="$current-instr/userinput"/>
86 <xsl:call-template name="process-prompt">
87 <xsl:with-param
88 name="instructions"
89 select="$instructions[position()>1]"/>
90 <xsl:with-param name="root-seen" select="boolean(0)"/>
91 <xsl:with-param name="prompt-seen" select="boolean(0)"/>
92 </xsl:call-template>
93 </xsl:otherwise><!-- no role -->
94<!--============================================================-->
95 </xsl:choose>
96 </xsl:template>
97
98 <xsl:template match="prompt"/>
99</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.