[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] FIRST-OCCURENCE
Subject: Re: [xsl] FIRST-OCCURENCE From: naha@xxxxxxxxxx Date: Tue, 05 Mar 2002 11:52:09 -0500 (EST) |
Quoting Kim Durand <vsd18@xxxxxxxxxxxxxx>: [...] > i run a for-each for colors and want to attach ***** to the text > of first occurence of the color with type = 'rude' and display the > subsequent color text in a normal way > example, > i want the display of the above xml file to be like .. > *****red > orange > yellow "rude" being one of those off-colors? :-) (sorry, couldn't resist) Now that I've subjected you to the stupid pun I guess I owe you an answer. Assuming you have a node set of the coloer elements you care about in a variable named color-elements, then your for-each would look like <xsl:for-each select="$color-elements"> ... </xsl:for-each> You already knew this but bear with me. The first such color element whose type was 'rude' would be $color-elements[@type='rude'][1] The function generate-id() returns a unique identifier for a node, so we can determine if two nodes are the same node by seeing if their generated ids are equal generate-id($node1) = generate-id($node2) So, given the variable color-elements as described above <xsl:variable name="first-rude" select="$color-elements[@type='rude'][1]"/> <xsl:for-each select="$color-elements"> <xsl:if test="gener"ate-id(.) = generate-id($first-rude)"> <xsl:text>*****</xsl:text> </xsl:if> <!-- output the color name. normalize-space() removes leading and trailing whitespace. --> <xsl:value-of select="normalize-space(.)"/> </xsl:for-each> I've not tried this and I may be a bit rusty, but it will atleast outline how to do this. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] FIRST-OCCURENCE, Kim Durand | Thread | Re: [xsl] FIRST-OCCURENCE, Corey_Haines |
Re: [xsl] Resetting context to main, Costantino Sertorio | Date | [xsl] Lost Attributes?, Mike Ferrando |
Month |
Keywords