Reputation: 470
I am trying to create a reusable XSLT 1.0 function to remove a delimiter from any given string. Since I am working in a 3rd party application, the source XML and the compiler are black-box to me. The code I have produces good results if I use:
<xsl:value-of select="translate(variable,$delimiter,'')"/>
for each string I want to sanitize, but if I try to use the function I wrote below by calling <xsl:value-of select="ecm:rmdelim(variable)"/>
the results truncate at that point. What am I missing?
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:func="http://exslt.org/functions"
xmlns:ecm="http://tempuri.org/mynamespace"
exclude-result-prefixes="ecm"
extension-element-prefixes="func"
>
<xsl:output method="text" />
<!-- set the delimiter -->
<xsl:variable name="delimiter" select="'^'"/>
<!-- create function to remove delimiters from a string -->
<func:function name="ecm:rmdelim">
<xsl:param name="arg"/>
<func:result select="translate($arg,$delimiter,'')"/>
</func:function>
Upvotes: 0
Views: 190
Reputation: 117102
You can write your own functions only if your processor supports the EXSLT func:function
extension element. Very few processors do. You can find out if your does by looking at the result of:
<xsl:value-of select="element-available('func:function')"/>
Since I am working in a 3rd party application, the source XML and the compiler are black-box to me.
You can see what the source XML looks like by applying the identity transform to it.
And you can identify the processor by:
<xsl:value-of select="system-property('xsl:vendor')"/>
Upvotes: 1