How I could fetch first three character from a string variable

Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2009
Posts: 2
Reputation: MJUGRAN is an unknown quantity at this point 
Solved Threads: 0
MJUGRAN MJUGRAN is offline Offline
Newbie Poster

How I could fetch first three character from a string variable

 
-2
  #1
Sep 25th, 2009
Hi,

How I could fetch first three character from a string variable.
Say for I fetched a variable message="ABCtest" .... now I want to test that the first three character matches ABD or not .. How I could code to achieve in xslt?

Cheers
Manish
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 858
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 139
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: How I could fetch first three character from a string variable

 
0
  #2
Sep 25th, 2009
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: m.asfak is an unknown quantity at this point 
Solved Threads: 0
m.asfak m.asfak is offline Offline
Newbie Poster
 
1
  #3
Oct 21st, 2009
Originally Posted by MJUGRAN View Post
Hi,

How I could fetch first three character from a string variable.
Say for I fetched a variable message="ABCtest" .... now I want to test that the first three character matches ABD or not .. How I could code to achieve in xslt?

Cheers
Manish
I am giving answer focusing on the bold line (that I've made)....

Let's consider the following example
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <abc>
  3. <def>
  4. </def>
  5. <ghi>
  6. <jkl>ABCdef</jkl>
  7. </ghi>
  8. <jkl/>
  9. </abc>

I want to print ABCdef if it contain ABC in the first three letters....

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  3. <xsl:template match="/">
  4. <xsl:apply-templates/>
  5. </xsl:template>
  6.  
  7. <xsl:template match="jkl">
  8. <xsl:if test="substring(.,1,3)='ABC'">
  9. <xsl:value-of select="."/>
  10. </xsl:if>
  11. </xsl:template>
  12.  
  13. </xsl:stylesheet>

Hope you will get the answer.

Regards.
Reply With Quote Quick reply to this message  
Reply


Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC