Arran
Arran

Reputation: 157

How would I get the last character of a string in XSLT in order to add it to my HTML output?

I am very new to XSLT and need to grab only the last letter of an XML value and add that character to my HTML output.

Upvotes: 6

Views: 21611

Answers (1)

zx485
zx485

Reputation: 29032

Use the XPath expression

substring(., string-length(.), 1)

or, in an XSLT way

<xsl:value-of select="substring(., string-length(.), 1)" />

This works, because XPath starts counting at 1 and not 0.

Upvotes: 17

Related Questions