xsl-list
[Top] [All Lists]

RE: No to display the values which are already existing

2003-06-25 10:48:15
Hi

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Dhananjay Pitani
Sent: Wednesday, June 25, 2003 6:23 PM
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] No to display the values which are already existing


This is my xml

<Store>
  <Title>
        <Author>Steve</Author>
        <Name>XSL</Name>
  </Title>
  <Title>
        <Author>Steve</Author>
        <Name>XML</Name>
  </Title>
  <Title>
        <Author>Dan</Author>
        <Name>HTML</Name>
  </Title>
  <Title>
        <Author>Dan</Author>
        <Name>XSL</Name>
  </Title>
</Book>

I want to display the above xml as a html table with two 
columns Author and 
Titlle. My task is to display the Author's name only once. 
The output should 
be like this

Author      Title

Steve        XSL
                XML
Dan           HTML
                XSL


You could use a variation of the muenchian method

 <xsl:key match="Title" name="list" use="Author"/>
 <xsl:template match="Store">
  <table>
   <tr>
    <td>Author</td>
    <td>Title</td>
   </tr>
   <!-- instead of applying just to the first element of each group apply to
all -->
   <xsl:apply-templates/>
  </table>
 </xsl:template>
 <xsl:template match="Title">
  <tr>
   <td>
    <!-- display the Author if this is the first element of the group -->
    <xsl:if test="generate-id()=generate-id(key('list',Author))">
     <xsl:apply-templates select="Author"/>
    </xsl:if>
   </td>
   <td>
    <xsl:apply-templates select="Name"/>
   </td>
  </tr>
 </xsl:template>


Hope this helps you. 



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