|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
XSL: Accessing previous node element
XML:
Code:
<articles> <article> <ArticleID>756</ArticleID> <ArticleDate>16/07/2004</ArticleDate> <Expiry>01/01/2012</Expiry> </article> <article> <ArticleID>755</ArticleID> <ArticleDate>11/06/2003</ArticleDate> <Expiry>01/01/2012</Expiry> </article> </articles> XSL: Code:
<xsl:template match="article">
<xsl:param name="currentyear" select="substring(ArticleDate, 7, 4)"/>
<xsl:choose>
<xsl:when test="position()=1">
<tr><td><xsl:value-of select="$currentyear"/></td></tr>
</xsl:when>
<xsl:otherwise>
<xsl:if test="(position()-1)substring(ArticleDate, 7, 3)!=$newyear">
<tr>
<td><xsl:value-of select="$newyear"/></td>
</tr>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<tr><td valign="top"><xsl:apply-templates select="files"/>
</td></tr>
</xsl:template>
I'm trying to print a list of articles ordered by descending date and grouped by year. So when the year changes from 2004 to 2003, print the year once, list the rest of the 2003 articles and so on (2002,2001). i.e. 2004 article1 article2 article3 2003 article4 article5 2002 article6 The crux of the problem is this line Code:
<xsl:if test="(position()-1)substring(ArticleDate, 7, 3)!=$newyear"> I want to access the previous article's date and the year within it and test it against the current year. Cheers, Mick |
|
#2
|
|||
|
|||
|
sry, using MSXML2.DOMDocument
|
|
#3
|
|||
|
|||
|
Worked it out:
substring(preceding-sibling::article[1]/ArticleDate, 7, 4) |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL: Accessing previous node element |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|