How to get last value in delimited string?

Discussion in 'XML' started by bearclaws, Jan 28, 2005.

  1. bearclaws

    bearclaws Guest

    I'm new to XML/XSL and need to get the last value from a string that
    looks like this (where the colon is the delimiter)...

    Computers:Drives:Firewire:Hard Drive

    I have an XSL file that gets this whole string passed to it as a
    variable, but I just want to write "Hard Drive" to the screen.
    Any suggestions?

    Thanks,
    BC
     
    bearclaws, Jan 28, 2005
    #1
    1. Advertising

  2. bearclaws

    Joris Gillis Guest

    Tempore 19:00:10, die Friday 28 January 2005 AD, hinc in foro {comp.text.xml} scripsit bearclaws <>:

    > Computers:Drives:Firewire:Hard Drive
    >
    > I have an XSL file that gets this whole string passed to it as a
    > variable, but I just want to write "Hard Drive" to the screen.
    > Any suggestions?

    Hi,

    this is an XSLT1.0 solution:

    <xsl:template name="tail">
    <xsl:param name="string" select="."/>
    <xsl:choose>
    <xsl:when test="substring-after($string,':')">
    <xsl:call-template name="tail">
    <xsl:with-param name="string" select="substring-after($string,':')"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:eek:therwise>
    <xsl:value-of select="$string"/>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:template>call the template with e.g.:

    <xsl:call-template name="tail">
    <xsl:with-param name="string" select="$variable"/>
    </xsl:call-template>

    (by default, it will select the string value of the context node)

    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Deserta faciunt et innovationem appelant
     
    Joris Gillis, Jan 28, 2005
    #2
    1. Advertising

  3. bearclaws

    bearclaws Guest

    This worked perfectly :)

    Can you recommend any sites or books that will help me learn more about
    XSLT (i.e. with examples like the one you provided)?
    Many thanks!

    >>BC
     
    bearclaws, Jan 28, 2005
    #3
  4. bearclaws

    Joris Gillis Guest

    Tempore 21:28:34, die Friday 28 January 2005 AD, hinc in foro {comp.text.xml} scripsit bearclaws <>:

    > Can you recommend any sites or books that will help me learn more about
    > XSLT (i.e. with examples like the one you provided)?


    This is a good site:
    http://www.jenitennison.com/xslt/

    I myself learned XSLT with experimenting and reading this newsgroup.
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    "Et ipsa scientia potestas est" - Francis Bacon , Meditationes sacrae
     
    Joris Gillis, Jan 29, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sangram
    Replies:
    16
    Views:
    2,029
  2. Johny
    Replies:
    8
    Views:
    398
  3. RyanL
    Replies:
    6
    Views:
    701
    Paul McGuire
    Aug 28, 2007
  4. Niraj Khandwala

    Get tab delimited results

    Niraj Khandwala, Jul 31, 2004, in forum: ASP General
    Replies:
    5
    Views:
    121
    Niraj Khandwala
    Aug 2, 2004
  5. Sébastien Maurette
    Replies:
    3
    Views:
    147
    David Vallner
    Oct 2, 2006
Loading...

Share This Page