I'm pretty new to XSL(T). I'm not sure its relevant but I'm working with IBM DataPower.
I'm trying to use XSL to parse an incoming URI which looks like this:
http://ip:port/Nucleus_v2.9.3/SomeEndPoint
I wish to extract the version (2.9.3) into one variable and the destination (SomeEndPoint) into a second variable. I'm attempting to use a recursive template that takes two parameters (the above URI and the slash character). Within the template I would like to use an element that will trace thru the URI and capture both values into variables.
<xsl:template name="parseIncomingURI"> <xsl:param name="string" /> <xsl:param name="char" /> <xsl:choose> <xsl:when test="contains($string, $char) and contains($string, 'Nucleus_v')"> <xsl:call-template name="parseIncomingURL"> <xsl:with-param name="string" select="substring-after($string, $char)" /> <xsl:with-param name="char" select="$char" /> </xsl:call-template> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> </xsl:template>
I'm not sure what I'm attempting is possible and I may be misunderstanding what a template is meant to deliver. I want to assign the version in the "when" element above and then assign the end point variable in the "otherwise" (which would trigger after the last slash is encountered in the recursion).
For what it is worth, I simply call this template elsewhere in the XSL and pass the original URI and a '/' character as the two initial parameters. I realize in the "when" element I would need to acquire the version thru some substring-before and substring-after functions. I don't have that code included here as I think it clutters the example.
Am I on the right track? Any help or pointers would be greatly appreciated. I'll be glad to edit and add more info as needed.
Thanks, Chris
I don't think you need a recursive template here. You could extract the version as:
<xsl:variable name="version" select="substring-before(substring-after(URI, 'Nucleus_v'), '/')" />
and the destination as:
<xsl:variable name="destination" select="substring-after(substring-after(URI, 'Nucleus_v'), '/')" />
This is a purely XSLT 1.0 solution; if you're using IBM DataPower, you also have access to the EXSLT Regular Expression extension functions (according to their documentation).