Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 493
  • Last Modified:

Extract the last word in an element tag XSLT

Greetings!

Is it possible to extract the last word in an element tag?

For example:

<TEXT> This is making me rip my hair out. </TEXT>

Is there a way to just get the last word, "out" out?  

I tried using the following, without success.

<xsl:param name="last" select="($arg/*[position() = last()])"/>

Any advice or guidance is greatly appreciated.

Best regards,
Jamie
0
jmc430
Asked:
jmc430
  • 4
  • 3
1 Solution
 
Geert BormansCommented:
Jamie,

"last" would only work for elements,
not for words seperated by spaces

you need to process the string recursively,
I will post an example in a minute


Cheers!
0
 
jmc430Author Commented:
Thanks Geert!!
0
 
Geert BormansCommented:
jmc430,

here it is
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <xsl:call-template name="getLastWord">
            <xsl:with-param name="strParam" select="normalize-space(//TEXT)"/>
        </xsl:call-template>
        </xsl:template>
    <xsl:template name="getLastWord">
        <xsl:param name="strParam"/>
        <xsl:choose>
            <xsl:when test="contains($strParam, ' ')">
                <xsl:call-template name="getLastWord">
                    <xsl:with-param  name="strParam" select="substring-after($strParam, ' ')"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise><xsl:value-of select="$strParam"/></xsl:otherwise>
        </xsl:choose>
       
    </xsl:template>
</xsl:stylesheet>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Geert BormansCommented:
Jamie,

in order for the recursive template to work,
I add a normalize-space in the first call to the template
the reason is that otherwise there is a trailing space (possibly)
that breaks the test

in the otherwise, you can call your remove trailing dot template to remove the '.' after the out

cheers

Geert
0
 
jmc430Author Commented:
Thanks so much Geert!  You're totally awesome
0
 
jmc430Author Commented:
:)!
0
 
Geert BormansCommented:
you are welcome
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now