XSLT: Match last text() descendant in an element

I am working on an XSLT (1.0) template that needs to match the last text node in an element that has a particular attribute and inject . The hard part is I need to know the last descendant, and not necessarily the last child. The schema is not consistent. Some text Some more text Some other text. SELECT ME The closest I have gotten is the following, but it selects the last text() on every element, not the last element with a text node (e3 in the example above). *[ancestor-or-self::*[@condition='optional']]/text()[last()]

Best Answer

Answers