Extracting Domain from URL in XSLT

I'd like to extract the domain out of a url such that the XSLT will convert a url like: http://www.multimap.com/map/browse.cgi?X=-8550000.33029827&Y=2025000.0309924&scale=1000000&coordsys=mercator 
to
www.multimap.com

Any ideas on a solid method to get this to look right?  I guess I could use javascript after displaying the page and getting the domain out of the location object, but I'd prefer to do it on the XSLT side.

TIA,
Yair
LVL 2
ylevielAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ChenChenCommented:
use substring-before() and substring-after() function in xslt:

for example, a xml is this:
<root>
<url>http://www.multimap.com/map/browse.cgi?X=-8550000.33029827&Y=2025000.0309924&scale=1000000&coordsys=mercator
</url>
<root>


then your xsl:

<xsl:variable name="url_ini" select="root/url"/>
<xsl:variable name="url_m" select="substring-before($url_ini,'/')"/>
<xsl:value-of select="substring-after($url_m,'//')"/>

0
dualsoulCommented:
the best will be switched to XSLT 2.0 and use built-in regular expressions support :)
but if you don't want to do it:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
      
      <xsl:template match="/">
        <xsl:variable name="url_ini" select="/root/url"/>        
        <xsl:variable name="url_minus_http" select="substring-after($url_ini,'http://')"/>
       
        <xsl:value-of select="substring-before($url_minus_http,'/')"/>             
      </xsl:template>
</xsl:stylesheet>

, sample xml is here (i used ChenChen sample):
<?xml version="1.0" encoding="UTF-8"?>
<root>
<url>
<![CDATA[http://www.multimap.com/map/browse.cgi?X=-8550000.33029827&Y=2025000.0309924&scale=1000000&coordsys=mercator]]>
</url>
</root>


, please note this method doen't respect cases, where you have no http:// , you can add this logic if you have such cases.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ylevielAuthor Commented:
ChenChen & dualsoul,

ChenChen: I have been unable to get your answer to work.  It simply returns nothing for the url's... can you check your xsl and be sure that it works?

dualsoul: your answer works wonderfully, however is limited to http:// only.  I do not worry about having no prefix... but I do have cases of
1.) file://
2.) https://
3.) ftp://

Is there a solution that will handle all of these if I can guarantee that one of the following will be used?

Will I have to force the script to check for the prefix of each one?  I'll mess around with it and see if I can produce one for all and post it.
0
ylevielAuthor Commented:
Using the above examples, I modified the XSL to read:

<xsl:variable name="url_ini" select="/root/url"/>
<!-- removed http from the second param -->
<xsl:variable name="url_minus_http" select="substring-after($url_ini,'://')"/>
<xsl:value-of select="substring-before($url_minus_http,'/')"/>

Works like a charm!

Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.