Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing multiple attributes differently. Need help 1

Status
Not open for further replies.

chantey

Instructor
Jan 28, 2004
11
0
0
GB
Hi,
I have the following extract from my XML:

<bookentry>
<authorgroup>
<author>
<firstname>Rebecca</firstname>
<surname>Mills</surname></author>
</authorgroup>
</bookentry>

<bookentry>
<authorgroup>
<author>
<firstname>Gary</firstname>
<surname>Evans</surname></author>
<author>
<firstname>Kevin</firstname>
<surname>Goldsmith</surname>
</author>
</authorgroup>
</bookentry>

Authorgroup can have more than one author. The first part has two authors and the second has one author.
I have listed just the surnames using an XSL stylesheet and it is displayed as:

Mills
EvansGoldsmith

But I want it to be displayed as:

Mills, R
Evans, G and Goldsmith, K

Can anyone help me?

Many thanks.
 
Code:
<xsl:template match="bookentry">
 <table>
  <tr>
   <td>
    <!-- for each author node in group -->
    <xsl:for-each select="authorgroup/author">

     <!-- if not the first author of this group add ' and ' -->
     <xsl:if test="position() &gt; 1">
      <xsl:text> and </xsl:text>
     </xsl:if>

     <!-- print surname -->
     <xsl:value-of select = "surname"/>

     <!-- if there is a firstname-node with text in it -->
     <xsl:if test="string-length(firstname) &gt; 1">
      <!-- add ', ' -->
      <xsl:text>, </xsl:text>
      <!-- add first character of firstname -->
      <xsl:value-of select = "substring(firstname,1,1)"/>
     </xsl:if>

    </xsl:for-each>
   </td>
  </tr>
 </table>
</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top