Re: [xsl] Multiple elements condition

Subject: Re: [xsl] Multiple elements condition
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 27 Aug 2007 11:07:26 -0400
At 2007-08-27 07:55 -0700, Maxine Pensyl-Johnson wrote:
I've been trying to wrap my head around this problem and so far have
only succeeded in creating a headache. I keep thinking I'm making it
more difficult than it needs to be. Your help is very much appreciated.
Thank you in advance.

Max

Saxon 6.5.5
XPATH 1.0

Problem: When there are two or more <para> tags inside of a <note> tag
output the <para> tags as a bulleted list. (Why didn't the author use a
bulleted list to begin with? I don't know).

Sure ... but what is the problem? There are a number of aspects of your XSLT and XSL-FO that should probably change based on what I read, but I can't tell which issue to focus on (but I can guess).


When you say you have a problem, what is happening that you do not want to happen?

Example:
                    <note>
                        <para>Misc text.</para>
                        <para>Misc text.</para>
                        <para>Misc text.</para>
                        <para>Misc text.</para>
                    </note>

Should transform to:

*Misc text.
*Misc text.
*Misc text.
*Misc text.

XSL Code:

        <xsl:template match="note">
                <fo:block keep-together="always">
                        <fo:block text-align="center"  font="bold 11pt
arial" space-before="3mm" >NOTE</fo:block>
                        <fo:block padding-left="30pt"
padding-right="30pt">

You should probably be using start-indent= and end-indent= instead of padding because of the interaction with other blocks and the nature of the background colour (though it may not matter in this particular case, padding is not typically used for indentation).


                                <xsl:choose>
                                        <xsl:when test="count(note/para)
> 1">

Here you are counting note/note/para because your current node is note ... this is probably what your question is ... given that your current node is note, you should only be counting the para children: count(para).


                                                <fo:character
character="&#x25A1;"/> <xsl:value-of select="para"/>

You needn't use fo:character above, and the space between the character and the paragraph will be lost because it is in the stylesheet white-space ... and given you are dealing with paragraphs of information you are approaching this incorrectly. You probably need to remove the block you had and replace it with something along the lines of:


  <xsl:for-each select="para">
    <fo:block start-indent="30pt" end-indent="30pt">
      <xsl:text>&#x25a1; </xsl:text>
      <xsl:apply-templates/>
    </fo:block>
  </xsl:for-each>

</xsl:when>
                                        <xsl:otherwise>
                                                <xsl:apply-templates/>

This now needs to be wrapped in <fo:block> after you remove it from after the note:


    <fo:block start-indent="30pt" end-indent="30pt">
      <xsl:apply-templates/>
    </fo:block>

But you really aren't clear which problem you are referring to, so hopefully one of the above will help.

. . . . . . . . . . Ken

--
Upcoming public training: XSLT/XSL-FO Sep 10, UBL/code lists Oct 1
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Jul'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread