Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lazy XSLT question

Status
Not open for further replies.

toolkit

Programmer
Aug 5, 2001
771
GB
Suffering a mental block. Anyone have a quick template to turn "some.string.with.delims.foo" to "foo"? I don't think the substring-after function will do the trick unless I recurse it?
 
Sussed it:
Code:
<xsl:template name="getLastToken">
    <xsl:param name="tokens"/>
    <xsl:variable name="cropped" select="substring-after($tokens,'.')"/>
    <xsl:choose>
        <xsl:when test="contains($cropped,'.')">
            <xsl:call-template name="getLastToken">
                <xsl:with-param name="tokens" select="$cropped"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$cropped"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
But is there an easier way for this?
Cheers, Neil
 
Code:
<xsl:template name="getLastToken">
    <xsl:param name="tokens"/>
    <xsl:variable name="cropped" select="substring-after($tokens,'.')"/>
    <xsl:choose>
        <xsl:when test="not(contains($tokens,'.'))">
            <xsl:value-of select="$tokens"/>
        </xsl:when>
        <xsl:when test="not(contains($cropped,'.'))">
            <xsl:value-of select="$cropped"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:call-template name="getLastToken">
                <xsl:with-param name="tokens" select="$cropped"/>
            </xsl:call-template>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top