'Verify href has a valid url or not xslt 1

I need to validate the url inside href tag. If that url is valid then do nothing else remove that href tag inside <a> tag. We can use any general regex or any other kind of url validation to do this that validates the href.

Example:

<a href="http://" rel="nofollow">tinyurl</a>
 <a href="https://stackoverflow.com/questions/ask" rel="nofollow">valid url</a>
 <a href="https://fanyi.baidu.com/?aldtype=16047###" rel="nofollow">invalid url</a>

Result:

 <a rel="nofollow">tinyurl</a>
  <a href="https://stackoverflow.com/questions/ask" rel="nofollow">valid url</a>
 <a rel="nofollow">invalid url</a>

Thanks in advance. Any clue/help given is appreciated. regex that can be helpful:

/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/


Solution 1:[1]

Michael Sperberg-McQueen has defined XSD types that match different flavours of URI in

http://www.w3.org/2011/04/XMLSchema/TypeLibrary-URI-RFC3986.xsd

and

http://www.w3.org/2011/04/XMLSchema/TypeLibrary-IRI-RFC3987.xsd

To see the way these complex regular expressions are constructed, view these documents at the raw XML level using (for example) curl.

Regular expressions can be used for pattern matching in XSLT 2.0, but there's no support in XSLT 1.0.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael Kay