1

I have this XML:

<path>/en/products/bike</path>

Is there an XSLT function that will return

/products/bike

?

Thanks for any help.

1
  • 4
    What are the criteria you want to match on? Do you want the substring starting from the fourth character, the substring following /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. Commented Sep 8, 2013 at 17:40

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.