I'm trying to detect a url or email in string element of xml file that this xslt is being applied to. This is the part of code I'm working with:
<xsl:template match="/contacts/contact/other-contact">
<xsl:value-of select="service"/>
<xsl:choose>
<xsl:when test="@type != ''">
<xsl:text>(</xsl:text>
<xsl:value-of select="@type"/>
<xsl:text>)</xsl:text>
</xsl:when>
</xsl:choose>
<xsl:text>: </xsl:text>
<xsl:choose>
<xsl:when test="matches(address,'(http(s?)://)?((www\.)?)(\w+\.)+.+')">
<a href="{address}"><xsl:value-of select="address"/></a>
</xsl:when>
<xsl:when test="matches(address,'[^@]+@[^\.]+\.\w+')">
<a href="mailto:{address}"><xsl:value-of select="address"/></a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="address"/>
</xsl:otherwise>
</xsl:choose>
<br/>
</xsl:template>
According to this answer the matches(var,regex) should just work, but it gives me this error:
xmlXPathCompOpEval: function matches not found
XPath error : Unregistered function
xmlXPathCompiledEval: 2 objects left on the stack.
The address is an element of /contacts/contact/other-contact
matchesfunction you need to at least use XPath 2, as done by XSLT 2 processors. The error message looks like libxslt to me which only supports XSLT and XPath 1.0, and, depending on the configuration, EXSLT functions like xmlsoft.org/XSLT/EXSLT/html/libexslt-exslt.html.xsltprocto compile the document. Not sure which version I have or how to update it.xsltproc -Vgave me this output:Using libxml 20904, libxslt 10129 and libexslt 817 xsltproc was compiled against libxml 20904, libxslt 10129 and libexslt 817 libxslt 10129 was compiled against libxml 20904 libexslt 817 was compiled against libxml 20904matches. Saxon 9 supports XSLT and XPath 2 or in 9.8 even XSLT 3 and XPath 3.1, it is available in a Java, a .NET and a C version.xsltprocso I'm not sure if I can use something else. Is there any other way to test for regex match with what I have access to?