Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7192823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:01:53+00:00 2026-05-28T20:01:53+00:00

I’m trying to write a function which gets the domain name from a URL

  • 0

I’m trying to write a function which gets the domain name from a URL text in XML file i.e http://www.example.com.

 <xsl:function name="fdd:get-domain">
    <xsl:param name="url"/>

    <xsl:analyze-string select="$url" regex="^(.*)://([a-zA-Z0-9\-\.]?[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?)(/.*)$">
        <xsl:matching-substring>
            <xsl:value-of select="regex-group(1)"/>
        </xsl:matching-substring>

        <xsl:non-matching-substring>
            <xsl:value-of select="false()"/>
        </xsl:non-matching-substring>

    </xsl:analyze-string>
 </xsl:function>

This function always returns false. I’m not sure what am I missing in this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:01:55+00:00Added an answer on May 28, 2026 at 8:01 pm

    Inside an attribute value every { and } must be doubled (in order to distinguish them from the single chars that denote an AVT. Just by doubling the curly braces:

    ^(.*)://([a-zA-Z0-9\-\.]?[a-zA-Z0-9\-\.]+\.[a-zA-Z]{{2,3}}(/\S*)?)(/.*)$
    

    with this correction, when called like this:

    fdd:get-domain('http://www.abc/cpm/page.aspx')
    

    the result is:

    http
    

    I guess that you really want to get the domain, as this modified code (both the regex expression and the regex-group index) does:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:fdd="some:fdd">
     <xsl:output method="text"/>
    
     <xsl:template match="/">
      <xsl:sequence select="fdd:get-domain('http://www.abc.com/cpm/page.aspx')"/>
     </xsl:template>
    
          <xsl:function name="fdd:get-domain">
            <xsl:param name="url"/>
    
            <xsl:analyze-string select="$url" regex=
    "^(.*)://([a-zA-Z0-9\-\.]?[a-zA-Z0-9\-\.]+\.[a-zA-Z]{{2,3}})(/\S*)?(/.*)$">
                <xsl:matching-substring>
                    <xsl:value-of select="regex-group(2)"/>
                </xsl:matching-substring>
    
                <xsl:non-matching-substring>
                    <xsl:value-of select="false()"/>
                </xsl:non-matching-substring>
    
            </xsl:analyze-string>
         </xsl:function>
    </xsl:stylesheet>
    

    When this transformation is applied on any XML document (not used), the wanted, correct result is produced:

    www.abc.com
    

    Update: As reminded by Michael Kay, the need to duplicate any curly braces can be avoided if the RegEx is specified as the context of a variable and this variable is referenced as an AVT in the regex attribute of xsl:analyze-string :

    <xsl:analyze-string select="$url" regex="{$vRegEx}"
                        flags="mx" >
    

    This has another benefit — we can split RegEx subexpressions on different lines and even intermix them with comments.

    Here is the refactored transformation:

    <xsl:stylesheet version="2.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:fdd="some:fdd">
         <xsl:output method="text"/>
    
     <xsl:variable name="vRegEx">
    
       ^(.*) <!-- The scheme -->
    
       ://
    
       ([a-zA-Z0-9\-\.]?[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}) <!-- The domain -->
    
       (/\S*)?(/.*)$  <!-- the path and query string -->
    
     </xsl:variable>
    
         <xsl:template match="/">
          <xsl:sequence select="fdd:get-domain('http://www.abc.com/cpm/page.aspx')"/>
         </xsl:template>
    
              <xsl:function name="fdd:get-domain">
                <xsl:param name="url"/>
    
                <xsl:analyze-string select="$url" regex="{$vRegEx}"
                                    flags="mx" >
                    <xsl:matching-substring>
                        <xsl:value-of select="regex-group(2)"/>
                    </xsl:matching-substring>
    
                    <xsl:non-matching-substring>
                        <xsl:value-of select="false()"/>
                    </xsl:non-matching-substring>
    
                </xsl:analyze-string>
             </xsl:function>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.