I have this XML:
<path>/en/products/bike</path>
Is there an XSLT function that will return
/products/bike
?
Thanks for any help.
You can use the substring-after function.
So, for example, the following XSLT stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="path">
<xsl:value-of select="substring-after(., '/en')"/>
</xsl:template>
</xsl:stylesheet>
when applied to your XML:
<path>/en/products/bike</path>
will give:
/products/bike
With XSLT 2.0 you can also use the replace() function, which accepts a regex pattern as the second parameter and an optional 4th parameter for regex flags.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="path">
<xsl:sequence select="replace(., '^/en','')"/>
</xsl:template>
</xsl:stylesheet>
/en, following the second forward slash, the second-to-last slash, etc? There are many ways to extract that particular substring, but some will presumably be more useful to you than others.