How to substring url in xslt

Posted on 2010-01-03
Medium Priority
Last Modified: 2013-11-18
I have a column in xslt called $fieldvalue which is a url field. I want to get a specific string in the URL and group by that value.

For example my URL is : http://www.test.com/hello/tools/image

I want to get always the value from the URL after http://www.test.com/, which in the above case is 'hello' and ignore the "/tools/image". The URL changes all the time but I want to grab the value after http://www.test.com/ "GET THIS VALUE"/"IGNORE THE REST".
And I want to group by other value by the above string that I got from the URL.


						<xsl:when test="$fieldtype='url'">
							<a href="{$fieldvalue}"><xsl:value-of select="$fieldvalue" />
						<xsl:when test="$fieldtype='user'">
							<xsl:value-of select="$fieldvalue" disable-output-escaping="yes" />
							<xsl:value-of select="hithighlightedproperties/HHTitle/text()" />

Open in new window

Question by:vmandem
  • 3
LVL 60

Expert Comment

by:Geert Bormans
ID: 26166706
}"><xsl:value-of select="substring-before(substring-after($fieldvalue, 'http://www.test.com/'), '/')"/>
LVL 60

Expert Comment

by:Geert Bormans
ID: 26166708
loose the }"> from my answer above

Author Comment

ID: 26167863
I noticed in my requirements sometimes in my url that I look for some names and want to grab that string and group by that string will all the results. For example I look for a string called Accountant in the URL:
http://www.test.com/hello/Accountant. Then the above substring scenario does not work. How to deal with that suituation. I have several cases where I know the keywords and want to check in the URL if that keyword exist and grab that string and group by the column. I can post my XSLStylesheet if you would like. please let me know.
LVL 60

Accepted Solution

Geert Bormans earned 300 total points
ID: 26170308
Your exact requirement is not clear to me, I must say,
but I believe you can get what you need by a combination of
- substring-before
- substring-after
- contains()

contains returns true if the string in the first argument contains the string in the second argument

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question