Index: BLFS/xsl/scripts.xsl
===================================================================
--- BLFS/xsl/scripts.xsl	(revision c048987a2cafde63c769ce727b1773da44e88f65)
+++ BLFS/xsl/scripts.xsl	(revision 183cc33453c848375145452a34a53668276bddc3)
@@ -541,14 +541,12 @@
 <!-- instructions run as root (configuration mainly) -->
       <xsl:when test="@role = 'root'">
+<!-- templates begin/end-root are in gen-install.xsl -->
         <xsl:if test="not(preceding-sibling::screen[1][@role='root'])">
-          <xsl:if test="$sudo = 'y'">
-            <xsl:text>sudo -E sh &lt;&lt; ROOT_EOF&#xA;</xsl:text>
-          </xsl:if>
+          <xsl:call-template name="begin-root"/>
         </xsl:if>
         <xsl:apply-templates mode="root"/>
+        <xsl:text>&#xA;</xsl:text>
         <xsl:if test="not(following-sibling::screen[1][@role='root'])">
-          <xsl:if test="$sudo = 'y'">
-            <xsl:text>&#xA;ROOT_EOF</xsl:text>
-          </xsl:if>
+          <xsl:call-template name="end-root"/>
         </xsl:if>
       </xsl:when>
@@ -556,7 +554,7 @@
       <xsl:otherwise>
         <xsl:apply-templates select="userinput"/>
-      </xsl:otherwise>
-    </xsl:choose>
-    <xsl:text>&#xA;</xsl:text>
+        <xsl:text>&#xA;</xsl:text>
+      </xsl:otherwise>
+    </xsl:choose>
   </xsl:template>
 
@@ -603,4 +601,10 @@
   <xsl:template match="screen" mode="config">
     <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
+<!-- if the preceding "screen" tag is role="root", and we are role="root"
+     the end-root has not been called. So do it -->
+      <xsl:if test="preceding-sibling::screen[1][@role='root'] and
+                    @role='root'">
+        <xsl:call-template name="end-root"/>
+      </xsl:if>
       <xsl:call-template name="set-bootpkg-dir">
         <xsl:with-param name="bootpkg" select="'bootscripts'"/>
@@ -608,6 +612,18 @@
                         select="id('bootscripts')//itemizedlist//ulink/@url"/>
       </xsl:call-template>
+<!-- if the preceding "screen" tag is role="root", and we are role="root"
+     the begin-root will not be called. So do it -->
+      <xsl:if test="preceding-sibling::screen[1][@role='root'] and
+                    @role='root'">
+        <xsl:call-template name="begin-root"/>
+      </xsl:if>
     </xsl:if>
     <xsl:if test="preceding-sibling::para[1]/xref[@linkend='systemd-units']">
+<!-- if the preceding "screen" tag is role="root", and we are role="root"
+     the end-root has not been called. So do it -->
+      <xsl:if test="preceding-sibling::screen[1][@role='root'] and
+                    @role='root'">
+        <xsl:call-template name="end-root"/>
+      </xsl:if>
       <xsl:call-template name="set-bootpkg-dir">
         <xsl:with-param name="bootpkg" select="'systemd-units'"/>
@@ -615,12 +631,29 @@
                         select="id('systemd-units')//itemizedlist//ulink/@url"/>
       </xsl:call-template>
+<!-- if the preceding "screen" tag is role="root", and we are role="root"
+     the begin-root will not be called. So do it -->
+      <xsl:if test="preceding-sibling::screen[1][@role='root'] and
+                    @role='root'">
+        <xsl:call-template name="begin-root"/>
+      </xsl:if>
     </xsl:if>
     <xsl:apply-templates select='.'/>
     <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts' or
                                                   @linkend='systemd-units']">
-      <xsl:text>
-popd</xsl:text>
+<!-- if the next "screen" tag is role="root", and we are role="root"
+     the end-root has not been called. So do it -->
+      <xsl:if test="following-sibling::screen[1][@role='root'] and
+                    @role='root'">
+        <xsl:call-template name="end-root"/>
+      </xsl:if>
+      <xsl:text>popd
+</xsl:text>
+<!-- if the next "screen" tag is role="root", and we are role="root"
+     the begin-root will not be called. So do it -->
+      <xsl:if test="following-sibling::screen[1][@role='root'] and
+                    @role='root'">
+        <xsl:call-template name="begin-root"/>
+      </xsl:if>
     </xsl:if>
-    <xsl:text>&#xA;</xsl:text>
   </xsl:template>
 
@@ -686,4 +719,10 @@
   </xsl:template>
 
+  <xsl:template match="text()">
+    <xsl:call-template name="remove-ampersand">
+      <xsl:with-param name="out-string" select="string()"/>
+    </xsl:call-template>
+  </xsl:template>
+
   <xsl:template match="text()" mode="root">
     <xsl:call-template name="output-root">
@@ -740,5 +779,8 @@
       </xsl:when>
       <xsl:otherwise>
-        <xsl:value-of select="$out-string"/>
+        <xsl:call-template name="remove-ampersand">
+          <xsl:with-param name="out-string" select="$out-string"/>
+        </xsl:call-template>
+<!--        <xsl:value-of select="$out-string"/> -->
       </xsl:otherwise>
     </xsl:choose>
@@ -890,5 +932,9 @@
           <xsl:when test="contains($outputstring,'&gt;/') and
                                  not(contains(substring-before($outputstring,'&gt;/'),' /'))">
-            <xsl:value-of select="substring-before($outputstring,'&gt;/')"/>
+            <xsl:call-template name="remove-ampersand">
+              <xsl:with-param name="out-string"
+                   select="substring-before($outputstring,'&gt;/')"/>
+            </xsl:call-template>
+<!--            <xsl:value-of select="substring-before($outputstring,'&gt;/')"/>-->
             <xsl:text>&gt;$PKG_DEST/</xsl:text>
             <xsl:call-template name="outputpkgdest">
@@ -897,5 +943,9 @@
           </xsl:when>
           <xsl:when test="contains($outputstring,' /')">
-            <xsl:value-of select="substring-before($outputstring,' /')"/>
+            <xsl:call-template name="remove-ampersand">
+              <xsl:with-param name="out-string"
+                   select="substring-before($outputstring,' /')"/>
+            </xsl:call-template>
+<!--            <xsl:value-of select="substring-before($outputstring,' /')"/>-->
             <xsl:text> $PKG_DEST/</xsl:text>
             <xsl:call-template name="outputpkgdest">
@@ -904,5 +954,8 @@
           </xsl:when>
           <xsl:otherwise>
-            <xsl:value-of select="$outputstring"/>
+            <xsl:call-template name="remove-ampersand">
+              <xsl:with-param name="out-string" select="$outputstring"/>
+            </xsl:call-template>
+<!--            <xsl:value-of select="$outputstring"/>-->
           </xsl:otherwise>
         </xsl:choose>
@@ -911,3 +964,71 @@
   </xsl:template>
 
+  <xsl:template name="remove-ampersand">
+    <xsl:param name="out-string" select="''"/>
+    <xsl:choose>
+      <xsl:when test="contains($out-string,'&amp;&amp;&#xA;')">
+        <xsl:variable name="instruction-before">
+          <xsl:call-template name="last-line">
+            <xsl:with-param
+                 name="instructions"
+                 select="substring-before($out-string,'&amp;&amp;&#xA;')"/>
+          </xsl:call-template>
+        </xsl:variable>
+        <xsl:call-template name="remove-end-space">
+              <xsl:with-param
+                 name="instructions"
+                 select="substring-before($out-string,'&amp;&amp;&#xA;')"/>
+        </xsl:call-template>
+        <xsl:if test="contains($instruction-before,' ]') or
+                      contains($instruction-before,'test ') or
+                      contains($instruction-before,'pgrep -l')">
+          <xsl:text> &amp;&amp;</xsl:text>
+        </xsl:if>
+        <xsl:text>&#xA;</xsl:text>
+        <xsl:call-template name="remove-ampersand">
+          <xsl:with-param name="out-string"
+                          select="substring-after($out-string,
+                                                  '&amp;&amp;&#xA;')"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:copy-of select="$out-string"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template name="last-line">
+    <xsl:param name="instructions" select="''"/>
+    <xsl:choose>
+      <xsl:when test="contains($instructions,'&#xA;')">
+        <xsl:call-template name="last-line">
+          <xsl:with-param
+               name="instructions"
+               select="substring-after($instructions,'&#xA;')"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:copy-of select="normalize-space($instructions)"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template name="remove-end-space">
+    <xsl:param name="instructions" select="''"/>
+    <xsl:choose>
+      <xsl:when test="contains($instructions,'&#xA;')">
+        <xsl:copy-of select="substring-before($instructions,'&#xA;')"/>
+        <xsl:text>&#xA;</xsl:text>
+        <xsl:call-template name="remove-end-space">
+          <xsl:with-param
+               name="instructions"
+               select="substring-after($instructions,'&#xA;')"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:copy-of select="normalize-space($instructions)"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
 </xsl:stylesheet>
