'XSL logic to get the text immediate to closing child tag

Please help me to write XSL rule for the below requirement

Requirement: In an XML file inside the main tag if "IsValid : true" then check for the link's href attribute has either any one of the url("xyz.abc1.com" or "http://xyz.abc1.com") or ("https://xyz.abc1.com") and this link tag should be present after the "EGRID i.e (EGRID 1)" and after to the link "comma + Space (, ) should be there in the text". If the source xml doesn't match this condition display an error message as "InValid Content"

Input:

<main>
main text goes here <cs>IsValid : true</cs>
</main>
<p>
    This is a NXK text E<t>GRID 1</t><link href='xyz.abc1.com/rtt/XXXX'></link><sp>Help Page</sp>, Please click here
</p>

OutPut Message: InValid Content

I tried the below code but I am not getting an idea to how to proceed further

<xsl:template match='//main'>
<xsl:for-each select="cs">
<xsl:if test="(text()='IsValid : true')">
    <xsl:if test="(//p/link[matches(@href,'^(http://|https://)*(xyz.abc1.com)/[a-zA-z0-9]{3}/[a-zA-Z0-9]{4}$')])">
            <xsl:value-of select="saxon:line-number()"/>:<xsl:value-of select="saxon:column-number()"/><xsl:text>InValid Content</xsl:text>
            <xsl:message><xsl:value-of select="saxon:line-number()"/>:<xsl:value-of select="saxon:column-number()"/>InValid Content</xsl:message>
    </xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>


Sources

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

Source: Stack Overflow

Solution Source