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: trouble checking "cousins"of current node


Hi,  Chris,

As suggested by Wendell,

>you could devise a way of locating all events with
>the same element name ('war', 'civic-event' and so forth) and the same
>title. Keys would be a good way to do this.

a xslt list is attached for your reference to the solution of your problem.
So the problem of interruption by different element name  will not be an
issue.

The key is  to index the child node of document node  by using name of child
node
which is your class name.
  <xsl:key name="event" match="document/*" use="name()" />

Hope you find it useful.

Cheers,

Sun-fu Yang

sfyang@unisvr.net.tw

***  xsl  listing  **

<?xml version="1.0" encoding="big5" ?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
 <xsl:output method="html" indent="yes" />

  <xsl:key name="event" match="document/*" use="name()" />
  <xsl:variable name="uniEvent"
 select="root/document/*[count(. | key('event', name())[1]) = 1]"/>

 <xsl:template match="/">
 <table border="1" bgcolor="brown" width="80%">
<thead bgcolor="aqua"><th
>date</th><th>title</th><th>completeness</th></thead>
 <xsl:for-each select="$uniEvent">
 <tr bgcolor="yellow"><td colspan="3" align="center">
<xsl:value-of select="concat('class :', name())"/></td></tr>

 <xsl:apply-templates select="key('event',name())" mode="a"/>
 </xsl:for-each>
</table>
 </xsl:template>

 <xsl:template match="*" mode="a">
 <tr bgcolor="lightblue">
 <!--  parent node date attribute -->
 <td> <xsl:value-of select="../@date"/></td>
 <td><xsl:value-of select="@title"/></td>
 <td><xsl:value-of select="@complete"/></td>
</tr>
 </xsl:template>
</xsl:stylesheet>

**   xml ***
<root>
   <document date="2001.06.03">
      <war title="a" complete="yes"> . . . </war>
      <legislation title="b" complete="yes"> . . . </legislation>
      <war title="c" complete="no"> . . . </war>
   </document>
   <document date="2001.06.10">
      <civil-event title="d" complete="yes">  . . . </civil-event>
    <war title="c" complete="continued"> . . . </war>
   </document>
   <document date="2001.06.17">
      <war title="c" complete="continued"> . . . </war>
      <exploration title="e" complete="yes"> . . . </exploration>
   </document>
</root>


 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]