[thelist] XSL: current node question

Jonathan Chard jonathan at familygenetix.com
Mon Apr 2 04:54:25 CDT 2001


>	<xsl:template match="anne|betty|cindy">
>		<div class="...">
>			[more stuff in here]
>		</div>
>	</xsl:template>
>
>what do I do if I want the class on that <div> to be anne, or betty, or
>cindy, depending on the context?

I think that to get the text of the current node, you use

<xsl:value-of select="."/>

So, using ppk's code as a basis, it would be

<xsl:template match="anne|betty|cindy">
<div>
<xsl:attribute name="class">
<xsl:value-of select="."/>
</xsl:attribute>
</div>
</xsl:template>

I don't think there's any such xsl tag as <xsl:eval>!

We've got the Wrox XSLT Programmers Reference here in work, it's pretty
good. I recommend getting it if you're finding that the book you've got is a
bit thin. This one certainly isn't (are they ever?!)

And if you want an XSLT processor, you can use HTML Kit with a plugin from
unicorn enterprises <http://www.unicorn-enterprises.com/>. It works pretty
well for me, esp. as it shows you the output, unlike 'extended' IE5. And
it's free, unlike XMLSpy.

Hope this helps. Good luck. It's a bit of a learning cliff, but worth it in
the end.

Jon Chard.
PS. Your current xml isn't very extensible, e.g. what happens if you add
'alice'? You've got to change your xsl to reflect it. You might be better
off using xml like:
<root>
<person name="anne"/>
<person name="betty"/>
<person name="cindy"/>
</root>

And xsl as

<xsl:template match="person">
<div class="@name">
[more stuff here]
</div>
</xsl:template>

Then you can add as many names as you like. Just a suggestion... Obviously
this depends on what you want in [more stuff here] but ... it's up to you.





More information about the thelist mailing list