|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: FIRST-OCCURENCE
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








