Thanks again, Bob. I just applied the customization you suggested and it worked 
exactly the way I wanted it to.

Eric

-----Original Message-----
From: Bob Stayton [mailto:[email protected]] 
Sent: Tuesday, April 09, 2013 8:57 AM
To: Eric Nordlund; [email protected]; [email protected]
Subject: Re: [docbook-apps] Gentext for performance="optional"?

Hi Eric,
The line break after your Optional text happens because the para element 
processed by the xsl:apply-templates generates its own nested fo:block, which 
starts on a new line.

The trick here is to get the optional text inside the block of the first para 
of the step, which can be accomplished by creating a customized template for 
that para.  Try copying the template with match="para" from fo/block.xsl and 
modifying it with something like the following:

<xsl:template match="step[@performance = 'optional']/*[1][self::para]">
  <xsl:variable name="keep.together">
    <xsl:call-template name="pi.dbfo_keep-together"/>
  </xsl:variable>
  <fo:block xsl:use-attribute-sets="para.properties">
    <xsl:if test="$keep.together != ''">
      <xsl:attribute name="keep-together.within-column"><xsl:value-of
                      select="$keep.together"/></xsl:attribute>
    </xsl:if>
    <xsl:call-template name="anchor"/>
    <xsl:text>(Optional) </xsl:text>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

The biggest change is in the match attribute.  It selects the first child 
element of an optional step *if* it is a para.  The problem is that the first 
child element of step does not have to be a para; it could be a list or other 
kind of block element.  For such cases, I would retain your customization of 
step that puts the Optional text on its own line, but make it conditional on 
the first child not being a para:

 <xsl:when test="@performance='optional' and not(child::*[1]/self::para)">

Those two templates would cover the two cases of para and not para.

I think it would be good for the stylesheets to support @performance since that 
attribute has been in the DocBook schema for a long time. It needs to 
use the gentext code, though.   I'll look into it.

Bob Stayton
Sagehill Enterprises
[email protected]


From: Eric Nordlund
Sent: Monday, April 08, 2013 11:34 PM
To: [email protected] ; [email protected]
Subject: RE: [docbook-apps] Gentext for performance="optional"?


Thanks Dean, but that won’t work for what I want to do. I want to insert the 
text “(Optional) “ into the first paragraph inside a step that has the 
performance=”optional” attribute. And so far I have gotten only this close:

I modified a the procedure/step template in lists.xsl to check each step for 
the attribute, and then insert a <xsl:text>(Optional) </xsl:text> snippet in 
front of the fo:block that contains the step. This method puts the
“(Optional) “ right where I want it to be, but then the step text starts one 
line below where I want it to.

Is there a way for me to insert the text into the 1st para child of <step>? 
I figured out a way to do that with concat(‘(Optional) ‘,descendant-or-child), 
but that seems to break when any children of the para element have attributes 
(like linkend).

Is there really no standard way to style an optional step in docbook-xsl?

Thanks again, I’ll include my hack below in case anyone comes across this later 
who is looking for the same thing (look for the xml:choose surrounding the 
performance=”optional”).

Eric
--------------------------------

            <!-- Add "(Optional) " to steps that have the 
performance="optional" attribute set -->
            <xsl:template match="procedure/step|substeps/step">
                        <xsl:variable name="id">
                                    <xsl:call-template name="object.id"/>
                        </xsl:variable>

                        <xsl:variable name="keep.together">
                                    <xsl:call-template 
name="pi.dbfo_keep-together"/>
                        </xsl:variable>

                        <fo:list-item
xsl:use-attribute-sets="list.item.spacing">
                                    <xsl:if test="$keep.together != ''">
                                                <xsl:attribute 
name="keep-together.within-column"><xsl:value-of
                                                            
select="$keep.together"/></xsl:attribute>
                                    </xsl:if>

                                    <fo:list-item-label 
end-indent="label-end()">
                                                <fo:block id="{$id}">
                                                            <!-- dwc: fix for 
one step procedures. Use a bullet if there's no step 2 -->
                                                            <xsl:choose>
                                                                        
<xsl:when
test="count(../step) = 1">
                                                                             
        <xsl:text>•</xsl:text>
                                                                        
</xsl:when>
                                                                        
<xsl:otherwise>
                                                                             
        <xsl:apply-templates select="." mode="number">
                                                                             
                    <xsl:with-param name="recursive" select="0"/>
                                                                             
        </xsl:apply-templates>.
                                                                        
</xsl:otherwise>
                                                            </xsl:choose>
                                                </fo:block>
                                    </fo:list-item-label>
                                    <xsl:choose>
                                                <xsl:when 
test="@performance='optional'">
                                                            <fo:list-item-body 
start-indent="body-start()">
                                                                        
<fo:block>
                                                                             
        <xsl:text>(Optional) </xsl:text>
                                                                             
        <xsl:apply-templates/>
                                                                        
</fo:block>
                                                            </fo:list-item-body>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                            <fo:list-item-body 
start-indent="body-start()">
                                                                        
<fo:block>
                                                                             
        <xsl:apply-templates/>
                                                                        
</fo:block>
                                                            </fo:list-item-body>
                                                </xsl:otherwise>
                                    </xsl:choose>
                        </fo:list-item>
            </xsl:template>


From: [email protected] [mailto:[email protected]]
Sent: Monday, April 08, 2013 4:08 PM
To: Eric Nordlund; [email protected]
Subject: Re: [docbook-apps] Gentext for performance="optional"?

Eric,
I use a template that placed a "checkbox" in front of the procedure step. 
You probably could adapt this template to do what you need.

Regards,
Dean Nelson

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY CHECKBOX1 "☐"> <!-- white square --> <!ENTITY CHECKBOX2 "☑"> <!-- 
white square with check in it--> <!ENTITY CHECKBOX3 "□"> <!-- white square --> 
<!ENTITY CHECKBOX4 "▢"> <!-- white square with rounded corners --> <!ENTITY 
CHECKBOX5 "⬚"> <!-- large white square --> <!ENTITY CHECKBOX6 "◯"> <!-- white 
circle --> <!ENTITY CHECKBOXSQ "[ ]"> <!-- brackets --> ]> <xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"; >

   <!-- This template places a checkbox before each step in a procedure
        if the procedure has a role="check" attribute. If the procedure also
        has a step with a role="nocheck" that step will be rendered without a
        checkbox.

        This is only accomplished if the parameter "met.procedure.checkbox" 
is not empty.
   -->
    <xsl:param name="met.procedure.checkbox">1</xsl:param>
    <xsl:param name="met.procedure.checkbox.type">&CHECKBOX1;</xsl:param>
    <xsl:param name="met.procedure.checkbox.size">100%</xsl:param>


  <xsl:template match="procedure[@role='check']//step">
    <xsl:variable name="id">
      <xsl:call-template name="object.id"/>
    </xsl:variable>

    <fo:list-item  xsl:use-attribute-sets="list.item.spacing">
      <fo:list-item-label end-indent="label-end()">
  <fo:block id="{$id}">
          <xsl:choose>
            <xsl:when test="count(../step) = 1">
              <xsl:text>•</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$met.procedure.checkbox != '' and 
not(@role='nocheck')">
                  <fo:block font-weight="bold" margin-left="-0.5cm" >
     <fo:inline vertical-align="middle" 
font-size="{$met.procedure.checkbox.size}">
      <xsl:value-of select="$met.procedure.checkbox.type"/>
     </fo:inline>
                    <xsl:apply-templates select="." mode="number">
                      <xsl:with-param name="recursive" select="0"/>
                    </xsl:apply-templates>.</fo:block>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:apply-templates select="." mode="number">
                    <xsl:with-param name="recursive" select="0"/>
                  </xsl:apply-templates>. </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </fo:block>
      </fo:list-item-label>
      <fo:list-item-body start-indent="body-start()">
        <fo:block>
          <xsl:apply-templates/>
        </fo:block>
      </fo:list-item-body>
    </fo:list-item>
  </xsl:template>
</xsl:stylesheet>




In a message dated 4/8/2013 2:22:04 P.M. Pacific Daylight Time, 
[email protected] writes:
Hello docbook-apps. I’ve been beating my head against the wall for a while 
on this one now and I’m hoping I can get a quick answer here.

I have some procedural steps that have the performance=”optional” attribute 
on them, and I want to have some generated text such as “(Optional) “ to 
appear before the step text so readers know that the step is optional. I can’t 
find anything anywhere regarding the styling of step in this fashion. Any 
ideas? I’m hoping there is a parameter I can set to make it easy, otherwise 
I can customize a template to insert the text based on an if statement.

How do you guys do this?

Eric Nordlund
Customer Documentation and Training
Cray Inc.
901 5th Ave
Seattle, WA 98164
(206)701-2232
 

Reply via email to