This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: conditional copying of nodes?


"Hewko, Doug" <Doug.Hewko@ccra-adrc.gc.ca> wrote

> I've got the copy working but how I can incorporate this into my sort? I am
> trying to copy the existing <member> tree to <newmember> for the sorting.

I'm not sure why you want to copy the member data. Actually,
i'm not sure why you want grouping.
I guess you want to have a list of all distinct groups, and a list
of the members within the groups.
Try the following:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:output method="html" encoding="ISO-8859-1"/>
  <xsl:strip-space elements="*"/>
  <xsl:key name="contacts-by-group" match="member" use="group" />
  
  <xsl:template match="teammembers">
    <html><head><title>Contacts by group</title></head>
      <body>
        <!-- iterate over distinct groups -->
        <xsl:for-each select="member/group[not(preceding::group=.)]">
          <xsl:sort select="."/>
          <h1>Group <xsl:value-of select="."/></h1>
          <!-- process all members of the current group -->
          <xsl:apply-templates select="key('contacts-by-group',.)">
            <xsl:sort select="name"/>
          </xsl:apply-templates>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="member">
    <h2><xsl:value-of select="name"/></h2>
    <p>Email: <xsl:value-of select="e_mail"/></p>
    <p>Phone: <xsl:value-of select="phone"/></p>
  </xsl:template>
  
</xsl:stylesheet>


HTH
J.Pietschmann

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]