As there are some operations not supported by the Stylesheet version 1.0 we developed a set of Extra functions that can be used in XSL transformations.
They all start with the fn: prefix and they require the namespace
xmlns:fn="http://www.teradp.com/schemas/GN4/1/Xslt"
to be declared in the stylesheet definition. The extra function are fully documented here.
Since the extra functions are built-in the GN4 core, they need a GN4 environment in order to be used/tested. This means that the rendering method that we had being used so far is no longer enough.
For this purpose we can use the command srv4 XSL.
Srv4 XSL XSL_fullpathname –in XML_fullpathname –out output_fullpathname
The command also has an extra parameter -pars serverName:xxx that can be used to read the $pars from the system.
Most commonly used extensions
Converts text with end of lines in a sequence of paragraphs nodes. This is the default behavior when the third parameter is omitted but it can also be used for different purpose Example This is a variation of the standard usage where the paragraph is delimited by a LineFeed followed by three spaces <!--> Creates paragraphs on 0a followed by 3 spaces </!--> <xmlText> <xsl:copy-of select="fn:paragraphs(Text,'p','
 ')/*" /> </xmlText> A different usage to generate an item’s list: it converts a character separated list (list or words separated by a – or a , or :) into an <item> list. This is what we have in the input file: <Keywords>UK-Consumer-Online shopping</Keywords> Here’s how we handle it: <xsl:if test="string(Keywords)"> <keywords> <!--> Split the keywords list on "-" </!--> <xsl:copy-of select="fn:paragraphs(Keywords,'item','-')/*" /> </keywords> </xsl:if> The output will be: <keywords> |
This function is commonly used to generate an abstract or summary of a piece of text or to display only a certain number of characters of a string Example Here we generate the summary element using the first 300 characters of the Text node: <summary> <xsl:value-of select="fn:trimText(Text,300,' ','...')" /> </summary> |
The replace function processes par1 looking for par2 and replacing it with par3. fn:replace($something,'^[ ]+','') Pay attention to is that the matching string (the second parameter par2) is a regular expression. In the example above it matches all the trailing spaces at the beginning of a line so the result of the replace is the input string without eventual spaces at the beginning of each line. Here’s another example of a very common replace: <xsl:variable name="apos">'</xsl:variable> <title> <xsl:variable name="title" select="//apcm:ContentMetadata/apcm:SlugLine" /> <xsl:variable name="temp" select="fn:replace(fn:replace($title, '‘', $apos),'’', $apos)" /> <xsl:value-of select="fn:replace(fn:replace($temp, '“', '"'),'”', '"')" /> </title> In this example we used the trick to place the single quote into a variable in order to be able to output it into a quoted string and then a series of nesting replace. |
The createGuid function generates a new global unique identifier (GUID) to be used as unique name, for example, into a <story>: <story name="{fn:createGuid()}" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > |
Apply a regular expression to text, returning the result as an XML fragment. It returns a single empty XML element if the expression does NOT match the text. If the expression matches the text, it returns a XML element with one sub-element (node[1]), containing the matched text, and one additional sub-element (node[2] node[3] node[n]) for each matched group. Example Here’s a sample that uses the applyRegExp to read a text wire captured from AFP: <xsl:variable name="stories" select="fn:paragraphs(.,'story','GLGL')/*" /> <xsl:for-each select="$stories"> <xsl:variable name="groups" select="fn:applyRegExp(text(),'\x01(.*)\x1f(.*)\x13\x11(.*)\r\n\x02(.*)\r\n(.*)\x03','s')" /> <xsl:if test="count($groups//group)>0"> <xsl:variable name="sourceId" select="$groups/*[2]" /> <xsl:variable name="catCode" select="substring($groups/*[3],9)" /> <xsl:variable name="slug" select="$groups/*[4]" /> <xsl:variable name="text" select="$groups/*[5]" /> <xsl:variable name="textParas" select="fn:paragraphs($text,'p','
	 ')" /> <xsl:variable name="textNodes" select="msxsl:node-set($textParas/*)" /> <xsl:variable name="header"> |
Conversion in T rendering mode
The ‘xmlMode’ is object type defined in GN4Archive.xsd (so specific to Tark4 and GN4). Objects of these type are the different possible ‘rendering modes’ – i.e. outputs – i.e. destinations for XML text. They are basically just a name and a description identifying a rendering mode that the system ‘knows’ about. |
The xmlFormat object type has a attribute ‘renders’ that is a multi-reference to xmlMode objects. Each reference has an extra attribute ‘xslt’ that contain the XSL transformation to be used to convert XML texts in that format to the referenced rendering mode. |
See also
http://forum.teradp.com/topic.asp?TOPIC_ID=709
How to test it http://forum.teradp.com/topic.asp?TOPIC_ID=647