Just a tiny XSLT tip

I 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.