[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Gowtham,
My mistake in the response (above). position() keeps in step with the position of a node wrt its position in a [selected] nodeset, not just its position in the original document. It's properties such as prior-sibling, etc, that don't change from their original values. The upshot being that you don't need node-set() for what you're trying to do.
The following XSL picks out just the nodes of interest, adding a 0/1 according as the picked-out node is even/odd in the new nodeset. The (position() - 1) business is just to translate position() to be 0-based. Just to verify, you may want to change the selection below to nodes that you know are even/odd in the input XML, and still see that they take on 0/1 attributes based on their position in the newly-selected nodeset.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="/">
<table>
<xsl:apply-templates select="/Codes/Code[Name = 30 or Name=50 or Name=60]"/>
</table>
</xsl:template>
</xsl:stylesheet>
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
RE: [xsl] Another Alternate table-row background color question - Using filters
Subject: RE: [xsl] Another Alternate table-row background color question - Using filters From: "Aron Bock" <aronbock@xxxxxxxxxxx> Date: Mon, 30 May 2005 21:26:52 +0000 |
Gowtham,
stylesheet will extract only some information (filter) from the XML and create a table. I want the rows in this table to have alternate background color. Because of the filter condition in the XSL, I cannot use the position() to check for odd/even rows. I need to (essentially) check the row number inserted into the HTML <TABLE>.
Here're 2 XSLT 1.0 options: split the transform into 2 stylesheets--the first picks out only the rows you want, and the second formats them into HTML, this time using position() to determine even/odd rows. Alternatively you could do this in 1 stylesheet if you're willingto use an extension function such as node-set(). The idea here is to create a variable containing the rows you want, then to iterate rows inthis variable, this time using position(). Something like so:
My mistake in the response (above). position() keeps in step with the position of a node wrt its position in a [selected] nodeset, not just its position in the original document. It's properties such as prior-sibling, etc, that don't change from their original values. The upshot being that you don't need node-set() for what you're trying to do.
The following XSL picks out just the nodes of interest, adding a 0/1 according as the picked-out node is even/odd in the new nodeset. The (position() - 1) business is just to translate position() to be 0-based. Just to verify, you may want to change the selection below to nodes that you know are even/odd in the input XML, and still see that they take on 0/1 attributes based on their position in the newly-selected nodeset.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="/">
<table>
<xsl:apply-templates select="/Codes/Code[Name = 30 or Name=50 or Name=60]"/>
</table>
</xsl:template>
<xsl:template match="Code"> <xsl:copy> <xsl:attribute name="color"> <xsl:value-of select="(position() - 1) mod 2"/> </xsl:attribute> <xsl:copy-of select="*"/> </xsl:copy> </xsl:template>
</xsl:stylesheet>
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Another Alternate table-r, Aron Bock | Thread | Re: [xsl] Another Alternate table-r, Dimitre Novatchev |
[xsl] EXSLT for MSXML4 (Was: Re: [x, Dimitre Novatchev | Date | [xsl] template name in attributes, Luke Ambrogio |
Month |