Just a tiny XSLT tip
Published on 20. June 2008 inI just discovered this little tip that is quite handy (and obvious, if you allready know it).
Imagine you have som xml like this:
<message> Thank god it is friday <from>Tony</from> </message>
Now, you would like to write out the actual message, and not who it is from.
If you use a regular value-of like this:
<xsl:value-of select="message" />
Then you will get "Thank god it is fridayTony", and I don't really want Tony's name in there. So I will do this instead:
<xsl:value-of select="message/text()" />
And voila, it only writes out "Thank god it is friday" and ignores the <from> element.
EDIT:
If you wanted to write out only the <from> element, you would do:
<xsl:value-of select="message/from" />
Related posts
Comments
Comments disabled
Comments are disabled for this post.

On 20. June 2008 by Warren Buckley
Yeh that's a handy tip - always useful to know.
//Warren
On 21. June 2008 by Tim Geyssens
Nice little tip, thanks !
Cheers,
Tim
On 27. June 2008 by salman Mubbashir
Nice tip.
but i wonder, what if you want the from part only.
can i write this
On 27. June 2008 by Cristian Vallarino
If you want the from part only you use:
On 27. June 2008 by Morten Bock
I'm sorry. The blog system shuts out all forms of tags in the comments. I will add the answer to the post above.
On 28. June 2008 by salman
@Morten,
Umbraco is all cool and everything.
but I'm at the bottom of the xslt mountain.
it would be nice if you could point me to the
roads leading up the mountain.
one more thing... I know about Umbraco's $currentpage
but do you think i could find some pointer & tips
about jow umbraco uses XSLT. coz i know i got to start
figure out how to pull in various data bits, templates, and navigation bits. some tips would be appreciated.
On 28. June 2008 by salman
just a heads up.
on ie6 i see a funny clock icon in the comments
sometimes its next date, other times its just hanging after the first or second comment line.
On 28. June 2008 by Morten Bock
For general XSLT tutorials, I really like w3schools:
http://w3schools.com/xsl/default.asp
Also this is more Umbraco specific:
http://umbraco.org/documentation/books/xslt-basics
I can also recommend installing Warrens Website package, and just mess around with the XSLT macros in that site, to learn by example.
On 28. June 2008 by salman Mubbashir
thanks