Regex remove word from XSLT

I need to write a regular expression to remove a word using XSLT.

I need to change the output of my XML file "detailpath" from:

/ Events / 262/26207

... simply:

262/26207

XSL:

<xsl:value-of select="detailpath"/>

How to remove "/ events /"?

Thanks in advance.

+2
source share
4 answers

The regex pattern will be simple '/events/'

You can use it in XSLT 2.0 replace () function calls:

<xsl:value-of select="replace(detailpath,'/events/','')"/>
Function

returns the string xs:, which is obtained by replacing each disjoint substring $ input that matches the given pattern $ with the occurrence of the replacement $ string.

You can specify flags

fn:replace( $input     as xs:string?,
            $pattern   as xs:string,
            $replacement   as xs:string) as xs:string

fn:replace( $input     as xs:string?,
            $pattern   as xs:string,
            $replacement   as xs:string,
            $flags     as xs:string) as xs:string
+3
source

, ( ) XPath 1.0:

substring(detailpath, 9 * starts-with(detailpath,'/events/'))
+2

Another XPath 1.0 solution (assuming there is only one instance of the replacement string) that will work no matter where the text fragment is in the string:

<xsl:value-of select="concat(substring-before(detailpath,'/events/'), 
                             substring-after(detailpath,'/events/'))" />
0
source

echo / events / 262/26207 | sed -e | / events / || g '

This works in bash on Solaris and, given the settings, should work in PHP, Javascript and Perl, as far as I know.

-1
source

Source: https://habr.com/ru/post/1786996/


All Articles