Using function from different namespace

Here should go questions about transforming XML with XSLT and FOP.
albrjens
Posts: 1
Joined: Mon Mar 21, 2022 12:08 pm

Using function from different namespace

Post by albrjens »

Hi,
I have a problem with this regex function for getting the ticket ID from the subject of an email

Code: Select all

<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
				xmlns:fn="http://www.w3.org/2005/xpath-functions">

.............................
			<xsl:variable name="aaVendorIncidentNumber">
				<fn:analyze-string select="$emailSubject" regex="\[Ticket\d{{10}}\]">
					<fn:matching-substring>
						<xsl:value-of select="."/>
					</fn:matching-substring>
				</fn:analyze-string>
			</xsl:variable>
....................
Input:

Subject: Re: [Ticket0123456789] Testmail

Expected Result: aaVendorIncidentNumber -> [Ticket0123456789]
Instead of the Matching Substring I get the hole emailbody. I suggest it has something to do with the different namespaces.
How can I edit it correctly?
Info: I don't know why but the x-path functions are not available in namespace xsl
Mircea
Posts: 131
Joined: Tue Mar 25, 2003 11:21 am

Re: Using function from different namespace

Post by Mircea »

Hello,

Please consider using the following code for your implementation:

Code: Select all

<xsl:variable name="aaVendorIncidentNumber">
  <xsl:value-of select="fn:analyze-string($emailSubject,'\[Ticket\d{10}\]')/fn:match"/>
 </xsl:variable>
Please note that the fn:analyze-string() function returns as a result a fn:analyze-string-result element.

Regards,
Mircea.
Mircea Enachescu
<oXygen> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply