convertMarkup XSLT extension

Build 1501 on 14/Nov/2017  This topic last edited on: 27/Oct/2016, at 13:42

GN4 features a XSLT extension function convertMarkup that reads XML text with 't' markup and converts it into the corresponding justification XML: it creates an article 'on the fly' reading the supplied XML, justifies it and then generates and return the justification XML.

Description

The function returns an XML element containing the HTML - it can be copied directly in the output or assigned to a variable for further processing.

The conversions do the following:

Removes from the input all the text in notes mode.

Removes from the input all the text that is declared to be NOT in the specified Web region.

Removes from the input all the text that is declared to be only IN a region different than the specified Web region.

Converts paragraphs to HTML 'p' tags.

Converts hard returns to HTML 'br' tags.

Converts bold text (markup >bd 1<...>bd 0<) to HTML 'bd' tags.

Converts italic text (markup >it 1<...>it 0<) to HTML 'it' tags.

Converts tables to HTML tables - using the 'table', 'tr' and 'td' HTML tags. The HTML tables have a class equal to the GN4 table name (if a name is assigned to the table).

Outputs all the 'external' tags in the text 'as-is' - checking their syntax but otherwise assuming that they are HTML tags. External tags with a wrong syntax are ignored or can generate an error.

Parameters

The first parameter is the source XML text using 't' markup, in other words, an XPath expression returning the XML nodes containing the 'T' markup. It can be something simple as the XML element with the markup in it or something more complex filtering out / selecting only part of a text.

$typeName is the name of the text object type to use - e.g. 'head', 'body', etc.

$format is either the database id or the path - expressed as <typography name>:<format name> - of the format (justification context) to use to justify the text

$region is either the database id or the path - expressed as <title name>:<region name> - of the target region. If empty or equal to zero indicates that there is no target region and so all the text should be in the output, regardless of their in region / not in region settings.

'p' is the default paragraph XML tag - used for paragraphs that cannot be matched to any of the schema XML elements

$remCodes is a comma-separated list of '>rem<' markup codes that should be stripped from the output. It can be empty, and in such a case there will be no stripping of notes mode text.

The last parameter is a Boolean indicating is the output should include the HTML tags. Note that, when calling the convertMarkup() method from inside a XSLT stylesheet, you should write false() or true() with parentheses or, alternatively, a XPath expression. Avoid writing false or true without parentheses because they are considered as a XPath expression and so their result is always false. Also the strings ‘false’ and ‘true’ with quotes are invalid, because a string in XSLT is always true.

The feed_ArticleXml.xml is an example feed configuration that outputs the justification XML of an article using 'convertMarkup':

It should be used like this:

  ../do.ashx?cmd=feed&ids=5875&name=articlexml&pars=region:Demo:Web;defaultFormat:Default:J;remCodes:1,2

where '5875' is the id of the article, 'Demo:Web' is the target region, 'Default:J' is the format to use for texts that don't already have an associated format and '1,2' are the >rem< codes to strip.

Example

Here is an example of a call:

  . . . 

  <xsl:copy-of select="edfn:convertMarkup(gn4:tText,$typeName,$format,$region,'p',$remCodes,false())"/>

  . . .