Convert Code Templates to External Author Actions
26 May 2021
Read time: 4 minute(s)
Describes how to bring code templates into a framework as author actions.
- Create a framework or extend an existing framework using a Framework extension script.
- Go to Export the code templates to a file named code-templates.xml. and
-
Create an XSLT file with the following content:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="3.0"> <xsl:output method="xml"/> <xsl:template match="//codeTemplateItem[field[@name='contentType']/String/text() = 'text/xml']"> <xsl:variable name="actionName" select="field[@name='renderString']/String/text()"/> <xsl:result-document href="externalAuthorActions/{$actionName}.xml"> <a:authorAction xmlns:a="http://www.oxygenxml.com/ns/author/external-action" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.oxygenxml.com/ns/author/external-action http://www.oxygenxml.com/ns/author/external-action/authorAction.xsd" id="{$actionName}"> <a:name><xsl:value-of select="$actionName"/></a:name> <a:description><xsl:value-of select="field[@name='descriptionString']/String/text()"/></a:description> <a:operations> <a:operation id="InsertFragmentOperation"> <a:xpathCondition>true()</a:xpathCondition> <a:arguments> <a:argument name="fragment"> <!-- Try parsing the fragment. if it succeeds, we basically unwrap it from the CDATA. --> <xsl:try select="parse-xml-fragment(field[@name='unparsedInsertString']/String/text())"> <xsl:catch> <!-- Parsing failed. It might have unresolved entities. Keep it in a CDATA. --> <xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text> <xsl:value-of disable-output-escaping="true" select="field[@name='unparsedInsertString']/String/text()" ></xsl:value-of> <xsl:text disable-output-escaping="yes">]]></xsl:text> </xsl:catch> </xsl:try> </a:argument> </a:arguments> </a:operation> </a:operations> <a:accessKey/> </a:authorAction> </xsl:result-document> </xsl:template> <xsl:template match="text()"/> </xsl:stylesheet>
- Create an XSLT Transformation scenario and apply the XSLT over the code-templates.xml file.
- Go to the directory of code-templates.xml and copy the generated externalAuthorActions to the framework directory (the directory with the framework extension script).
-
Create another XSLT with the following content, then create an XSLT Transformation scenario and apply
it over the code-templates.xml file.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="3.0"> <xsl:output method="xml" omit-xml-declaration="yes" indent="true"></xsl:output> <xsl:output method="xml"/> <xsl:template match="/"> <contentCompletion> <authorActions> <xsl:apply-templates/> </authorActions> </contentCompletion> </xsl:template> <xsl:template match="//codeTemplateItem[field[@name='contentType']/String/text() = 'text/xml']"> <xsl:variable name="actionName" select="field[@name='renderString']/String/text()"/> <addAction id="{$actionName}" inCCWindow="true"/> </xsl:template> <xsl:template match="text()"/> </xsl:stylesheet>
-
Copy the resulting
<contentCompletion>
into the Framework extension script root element.