Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 27th, 2013, 11:14 AM
Authorized User
 
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
Default Retreiving substring using XSLT

Hi All,

I have below XML element:

<userid>2000 2355 270427 269770</userid>

Using xslt I want to retrieve only '270427' string.

Could you please tell me how to do that.

Regards
Yunus
 
Old February 27th, 2013, 11:35 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Assuming XSLT 2.0
Code:
<xsl:template match="userid">
  <xsl:value-of select="tokenize(., ' ')[3]"/>
</xsl:template>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old February 27th, 2013, 12:18 PM
Authorized User
 
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Hi Martin,

Thanks for your reply. Sorry forgot to mentioned I am using XSLT 1.0.

Could you please help for 1.0.

Like to add one more thing, there can be more then four strins in the userid element i.e. <userid>2000 2355 22355 270427 269770</userid>

But I always want to retrieve second last string i.e '270427'.

Many thanks for your help.


-Nelly

Last edited by nelly78; February 27th, 2013 at 12:57 PM..
 
Old February 28th, 2013, 07:12 AM
Authorized User
 
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Hi All,

Could someone please give any idea.

-Nelly
 
Old February 28th, 2013, 07:25 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well which XSLT 1.0 processor do you use? Does it support an extension function like http://www.exslt.org/str/functions/tokenize/index.html? That could be used in a similar way as the XSLT 2.0 tokenize.
As for access the second last, you would use
Code:
<xsl:variable name="tokens" select="tokenize(., ' ')"/>
<xsl:value-of select="$tokens[last() - 1]"/>
respectively a similar extension function.

If you don't have an extension function then use a named, recursive template that does the tokenization. http://www.dpawson.co.uk/xsl/sect2/N...tml#d10127e349 should give you an idea.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old February 28th, 2013, 07:29 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Write a recursive template that accepts the string as input, after doing normalize-space(). Use substring-after() to get the "tail", i.e. the content after the first space. If the tail contains a space, recurse passing the tail as the argument. Otherwise, use substring-before() to get the the content before the first space, and that's your answer.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Retreiving single record in XSLT nelly78 XSLT 2 November 14th, 2009 11:52 AM
Convert substring to node set in XSLT 1.0 JessicaD XSLT 3 July 30th, 2009 02:51 PM
Retreiving value from InputBox maniatis1 Classic ASP Professional 1 January 4th, 2007 03:36 PM
retreiving data from URL pavanntcs Oracle 1 September 20th, 2006 02:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.