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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I produce one output for a list of dates that meet one month

Status
Not open for further replies.

BrandonPar

Programmer
May 20, 2002
2
GB
Hi,

I'm trying to look at a list of dates and if one of those dates is in january then produce an output. The problem i have is that i don't want to produce the output twice even if there are dates in January listed more than once.

The following XML produces Y twice in the January column

<?xml version=&quot;1.0&quot; ?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;island.xsl&quot;?>
<xmldata>
<workactivity>
<text>Absence</text>
<question>
<text>A Review Appointment must be made for Jarvis Cocker on 03/10/2001</text>
<date>
<day>01</day>
<month>01</month>
<year>1999</year>
</date>
<date>
<day>11</day>
<month>01</month>
<year>1999</year>
</date>
<date>
<day>11</day>
<month>02</month>
<year>1999</year>
</date>
</question>
<question>
<text>My second question</text>
<date>
<day>21</day>
<month>11</month>
<year>1999</year>
</date>
<date>
<day>07</day>
<month>07</month>
<year>2000</year>
</date>
</question>
</workactivity>
</xmldata>

Here is the stylesheet

<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>
<!-- <xsl:stylesheet xmlns:xsl=&quot; -->
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;
<xsl:template match=&quot;/&quot;>
<html>
<body>
<table border=&quot;2&quot; bgcolor=&quot;yellow&quot;>
<tr>
<th>Question</th>
<th>J</th>
</tr>
<xsl:for-each select=&quot;xmldata/workactivity/question&quot;>
<tr>
<td><xsl:value-of select=&quot;text&quot;/></td>
<td>
<xsl:for-each select=&quot;date&quot;>
<xsl:if test=&quot;month='01'&quot;>
Y
</xsl:if>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

If anybody can give me some pointers i would be very grateful.

Kind Regards,

Brandon Par
 
interesting...

try changing the for loop and use the distinct-values function like this:
...

<xsl:for-each select=&quot;xmldata/workactivity/question&quot;>
<tr>
<td><xsl:value-of select=&quot;text&quot;/></td>
<td>
<xsl:for-each select=&quot;distinct-values(date)&quot;>
<xsl:if test=&quot;month='01'&quot;>
Y
</xsl:if>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>

...

I dont have my debugger, but that should work :)

Matt
 
ack it doesnt.

apparently its an XQuery function... sorry.

still, you could write a function yourself to do the same thing...!
 
Hi Matt,

Thanks for your comments, i've found another way of doing it as follows.

<xsl:for-each select=&quot;date[month='01']&quot;>
<xsl:if test=&quot;position()=1&quot;>
<xsl:if test=&quot;status='completed'&quot;>
<img src=&quot;completed&quot; border=&quot;0&quot; alt=&quot;completed&quot;/>
</xsl:if>
</xsl:if>
</xsl:for-each>

The code uses a for loop on only months that match 01 and then if the position is equal to 1 i produce the output

regards,

Brandon Par
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top