[xsl] XSL selection question

Subject: [xsl] XSL selection question
From: jeremyf@xxxxxxxxxxx
Date: Mon, 4 Nov 2002 13:04:54 -0500
Hi All,
      I have an XML file such that:

<report>
-snip-
  <module-installation-requirements sectionID="4">
    <inst-part>
      <part-number>G4P5616EGPPAE500</part-number>
      <description>DESCRIPTION FOR INSTALLATION REQUIREMENTS</description>
      <inst-notes>
        <inst-note>
          <view>ENG</view>
          <note>
            <note-title>FREE FORM NOTE</note-title>
            <note-description>TEXT FOR FREE FORM NOTE</note-description>
          </note>
        </inst-note>
        <inst-note>
          <view>ENG</view>
          <note>
            <note-title>FREE FORM NOTE 2</note-title>
            <note-description>TEXT FOR FREE FORM NOTE 2</note-description>
          </note>
        </inst-note>
      </inst-notes>
    </inst-part>
  </module-installation-requirements>
-snip-
</report>

I want the following output



G4P5616EGPPAE500  DESCRIPTION FORINSTALLATIONREQUIREMENTS         ENG
FREE FORM NOTE    TEXT FOR FREE FORM NOTE

                                                            ENG
FREE FORM NOTE 2  TEXT FOR FREE FORM NOTE 2

Each of these is a row in my output. How do I select the number and
description the first time but not every time after until I reach a new
number?
I have a template that gives me the nodes, but I also need to handle
different views for the same part/description and potentially multiple
<note> items per view.
My templates look something like this:

-snip-

    <xsl:template match="module-installation-requirements">
      <!-- start of format specific setup -->
                  <fo:table height="1cm" table-layout="fixed">
                        <fo:table-column column-width="25cm"/>
                        <fo:table-body font-family="Times-Roman"
font-weight="bold" font-size="8pt">
                              <fo:table-row line-height="8pt">
                                    <fo:table-cell padding="8pt">
                                          <fo:block text-align="start"
height=".5cm">* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * </fo:block>
                                    </fo:table-cell>
                              </fo:table-row>
                              <fo:table-row line-height="8pt">
                                    <fo:table-cell padding="8pt">
                                          <fo:block text-align="center"
height=".5cm" font-weight="normal">.  .  .  MODULE INSTALLATION
REQUIREMENTS  .  .  .</fo:block>
                                    </fo:table-cell>
                              </fo:table-row>
                        </fo:table-body>
                  </fo:table>
                  <fo:table height="1cm" table-layout="fixed">
                        <fo:table-column column-width="6cm"/>
                        <fo:table-column column-width="4cm"/>
                        <fo:table-column column-width="2cm"/>
                        <fo:table-column column-width="4cm"/>
                        <fo:table-column column-width="8cm"/>
                        <fo:table-header font-family="Times-Roman"
font-weight="bold" font-size="8pt">
                              <fo:table-row line-height="10pt">
                                    <fo:table-cell padding="4pt">
                                          <fo:block text-align="start">PART
OR IDENTIFYING NUMBER</fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align
="start">DESCRIPTION</fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align
="center">VIEW</fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align
="center">NOTE TITLE</fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align="start">NOTE
DESCRIPTION</fo:block>
                                    </fo:table-cell>
                              </fo:table-row>
                        </fo:table-header>
                        <fo:table-body font-family="Times-Roman"
font-weight="bold" font-size="8pt">
      <!-- end setup -->
      <!-- call the template to format this section and pass the title -->
      <xsl:choose>
      <xsl:when test="*">
            <xsl:apply-templates/>
      </xsl:when>
      <xsl:otherwise>
            <fo:table height=".8cm" table-layout="fixed">
                  <fo:table-column column-width="25cm"/>
                  <fo:table-body font-family="Times-Roman" font-weight
="bold" font-size="8pt">
                        <fo:table-row line-height="10pt">
                              <fo:table-cell padding-top="8pt">
                                    <fo:block text-align="center" height
=".8cm">NO APPLICABLE DATA EXISTS</fo:block>
                              </fo:table-cell>
                        </fo:table-row>
                  </fo:table-body>
            </fo:table>
     </xsl:otherwise>
    </xsl:choose>
      <!-- start of clean up -->
                        </fo:table-body>
                  </fo:table>
      <!-- end clean up -->
    </xsl:template>

    <xsl:template match="inst-part">
      <!-- format the part number and description -->
      <!-- It is not that easy with FO -->
        <xsl:apply-templates select="inst-notes"/>
    </xsl:template>

    <xsl:template match="inst-note">
      <!-- format the output of the "view" value along -->
      <!-- with the note contents. This will not start -->
      <!-- at the beginning of the line.               -->
                              <fo:table-row line-height="10pt">
                                    <fo:table-cell padding="4pt">
                                          <fo:block text-align
="start"><xsl:value-of select="../../part-number"/></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align
="start"><xsl:value-of select="../../description"/></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align
="center"><xsl:value-of select="view"/></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align
="center"><xsl:value-of select="note/note-title"/></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align
="start"><xsl:value-of select="note/note-description"/></fo:block>
                                    </fo:table-cell>
                              </fo:table-row>
                        <xsl:for-each select="inst-note/note">
                              <fo:table-row line-height="10pt">
                                    <fo:table-cell padding="4pt">
                                          <fo:block text-align="start"/>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align="start"/>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align
="center"><xsl:value-of select="view"/></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align
="center"><xsl:value-of select="note-title"/></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="4pt" height
="1cm">
                                          <fo:block text-align
="start"><xsl:value-of select="note-description"/></fo:block>
                                    </fo:table-cell>
                              </fo:table-row>
                        </xsl:for-each>
    </xsl:template>

I am certain that I  am making this harder than it sould be, but I am still
having trouble.
Any help is appreciated.

Jeremy



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread