tags:

views:

35

answers:

4

I know it is so simple to some of you.

All I want to do is look through an xml doc and print out the xml entries that contain specific string fragments. The string value is passed to the xslt and the xml doc is looked at and if a word begins with the string expression it displays it.

What I have errors with the following message...

MM_XSLTransform error: Error while transforming: 'matches()' is an unknown XSLT function.

here is my code sample...

<xsl:stylesheet 
  version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml"&gt;
  <xsl:output method="html" encoding="utf-8"/>
  <xsl:param name="qString" />
  <xsl:template match="/">
    <xsl:for-each select="Products/Product">

        <xsl:if test="matches('/OldPN','$qString')">
          <xsl:value-of select="OldPN" /> - <xsl:value-of select="OldName" />
        </xsl:if>

    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

Any ideas? Would so appreciate help on this!

A: 

If you're using .NET, you can extend xslt by injecting your own IL methods from the host program. Adding regex support would be easy this way.

tdammers
A: 

Are you using an XSLT 2.0 processor?

Jim Garrison
That's what I don't know. I was told it had the latest and greatest. I have access to the server, how would I check for that?
Jimmmy
A: 

The matches function for regular expressions is new in xslt 2.0, which is probably not yet supported by your xslt processor. If you can use a plain string instead of a regular expression you can try either contains or starts-with instead.

In addition, in your example the second parameter must not be enclosed in quotes, since then you would be matching against the literal string "$qString" instead of the value of this parameter.

Jörn Horstmann
Thanks for that about the quotes. I kinda thought that would be the case after I get the "unknown XSLT function" out of the way.I'm thinking my problem is the lack of support for 2.0. "Contains" may work as you suggest, but aside from that it may be back to the drawing board for another solution.
Jimmmy
A: 

The underlying libxslt currently only supports (e)xslt 1.0.
But you can register php functions which e.g. makes preg_match() available.

see http://docs.php.net/xsltprocessor.registerphpfunctions

VolkerK