0

We've been pulling our hair out just trying to just trying to get a basic example of the XSLT replace function to work.

I'm leaving this text in tact for context, but you may want to skip to the update

We're using Mirth to pull in HL7 messages. We're unsure whether this supports XSLT version 2, but we believe it uses SAXON - http://saxon.sourceforge.net/, which purportedly does support XSLT2 and hence the replace function.

In any case, we tried using XSLTCake to try and get even a demo replacement to work, to no avail. We've seen this either referenced as replace or fn:replace as well as a couple other suggestions using other libraries.

If XSLT2 isn't supported by Mirth, we would need a workaround for XSLT1. We found one here: XSLT string replace - but have been unable to get this to work either.

This is a tough to get down to a single question as I'm asking alot, but here goes... Can anyone provide a working example of performing a regex replacement in an XSLT? Preferably one that will run in an online parser for reference.

Here's a sample - which apparently should work.1

Update

Thanks to Michael Kay for providing code below to determine XSLT version.

<!--Transformed using 1.0 provided by Apache Software Foundation (Xalan XSLTC)-->

So It turns out we were all wrong about Mirth using SAXON and hence supporting XSLT2. I'll update with our attempt at implementing the version 1 workaround.

1 Answer 1

3

First find out which XSLT processor you are using. This is straightforward: insert this

<xsl:comment>Transformed using <xsl:value-of select="system-property('xsl:version')"/> provided by <xsl:value-of select="system-property('xsl:vendor')"/></xsl:comment>

into your stylesheet to output a comment in your result document.

Once you know what programming language you are using, you can start thinking about writing code.

2

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.