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 November 28th, 2007, 05:04 AM
Registered User
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to asfak
Default A serious string problem. Urgent solution needed.

I am new in XSLT.

I need a solution in XSLT from the experts. Say I have a string
with the following values (on the left). I need to extract a substring with the value (on the right) which does not have any trailing dots.

Given sub string I need to extract
------------ ------------------------------
"1.2.1..." "1.2.1"
"1." "1"
"1.2.1.1.1." "1.2.1.1.1"
"1.2.1.2.1...." "1.2.1.2.1"

I think I can make you understand my problem. XSLT has so limited functions for string. I have coded like the following. I had a label attribute. I need to print the value of label attribute which is free of trailing dots. But surely this (my following code) does not work. It works only for the case "1." but not any of the above except "1.". For the case "1.2.1..." my code gives the output "1"


Code:
<xsl:variable name="labelValue" select="@label"/>
<xsl:choose>
    <xsl:when test="ends-with($labelValue,'.')">
        <xsl:value-of select="substring-before($labelValue,'.')"/>    
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="@label"/>
    </xsl:otherwise>
</xsl:choose>
Please give me a solution as quick as possible. I need it urgent.

regards,
Asfak

asfak
 
Old November 28th, 2007, 05:27 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

If you are using XSLT 2.0 then there is probably a way to do this using tokenize() function. Alternatively you are looking at a call to a recursive template.

/- Sam Judson : Wrox Technical Editor -/
 
Old November 28th, 2007, 06:08 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to be aware that when you say a problem is urgent, many people will avoid responding, because they prefer helping people who have time to study the answers carefully and learn from them.

The first thing to ask is: can you use XSLT 2.0 for this? You're using ends-with(), which is a 2.0 function, and that suggests you could use regular expressions, in which case you can use

replace($labelValue, '(^.*?)\.*$', '$1')

However, creative solutions are often possible in 1.0. I think you could solve this one by using translate() to translate "." into space, then using normalize-space(), then using translate() to translate spaces back into ".".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Grouping Solution needed matrixman XSLT 9 April 27th, 2007 07:55 AM
Dialog Problem -Urgent Help Needed jerusalem Visual C++ 0 January 6th, 2007 08:04 AM
Solution needed very urgent: fcntl and flock hariharan Visual C++ 1 November 22nd, 2005 09:07 AM
Urgent help needed! Compare a string to Sysdate in WroteForLuck Classic ASP Professional 1 July 17th, 2003 06:11 PM





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