I. This is an XPath 2.0 expression :
substring-after(tokenize($pUrl, '[?|&]')[starts-with(., 'v=')], 'v=')
creates the desired, correct result .
Alternatively, you can use a little shorter:
tokenize(tokenize($pUrl, '[?|&]')[starts-with(., 'v=')], '=')[2]
Here is the complete transformation of XSLT 2.0 :
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:param name="pUrl" select= "'http://www.youtube.com/watch?v=qadqO3TOvbQ&feature=channel&list=UL'"/> <xsl:template match="/"> <xsl:sequence select= "tokenize(tokenize($pUrl, '[?|&]')[starts-with(., 'v=')], '=')[2]"/> </xsl:template> </xsl:stylesheet>
When this conversion is applied to any XML document (not used), the desired, correct result is obtained :
qadqO3TOvbQ
II. This is an XPath 1.0 expression :
concat (substring-before(substring-after(concat($pUrl,'&'),'?v='),'&'), substring-before(substring-after(concat($pUrl,'&'),'&v='),'&') )
creates the desired result .
Please note :
Both solutions retrieve the desired string, even if the query string parameter named v
not the first, or even if it is the last.