Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

substring

xslt

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.

like image 961
Arran Avatar asked Jan 29 '17 05:01

Arran


People also ask

How do I select a substring in XSLT?

XSLT doesn't have any new function to search Strings in a reverse manner. We have substring function which creates two fields substring-before-last and substring-after-last.In XSLT it is defined as follows: <xsl:value-of select="substring (string name ,0, MAX_LENGTH )"/>...

Which symbol is used to get the element value in XSLT?

XSLT <xsl:value-of> Element The <xsl:value-of> element is used to extract the value of a selected node.

How do I concatenate strings in XSLT?

Concat function in XSLT helps to concatenate two strings into single strings. The function Concat() takes any arguments that are not the string is been converted to strings. The cardinality function passed over here in each argument should satisfy zero or one function() respectively.

What are the output format for XSLT?

XSLT uses the <xsl:output> element to determine whether the output produced by the transformation is conformant XML (<xsl:output method="xml"/> ), valid HTML (<xsl:output method="html"/> ), or unverified text (< xsl:output method="text"/> ).


1 Answers

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.

like image 191
zx485 Avatar answered Oct 06 '22 19:10

zx485