My XSLT files

Today wil probably be my last posting on XSLT. To help others I am uploading to XSLT scripts, a XML exporter config file and a plugins file. I will not be posting much in the next 2 weeks as I prepare for our K4 v6.3 launch on April 18.

You can download the files by clicking here.

 When a a user is finished with the Tag task the article automatically goes to the XML Tag task. The gear icon means that this is an automatic task. K4 will process the XML export, mark the task as completed and the status of the article will change to In CMS.

If we examine the contents of the automated task it is simply  conf=K4_XMLExporter_Config_WOL.xml. We could have added more commands here but simply stating the configuration file to use is sufficient. The configuration file will call the plugin file which in turn will call the XSLT files.

The config file template is well documented. The same template is used for config files triggered by the K4Server and for stand alone version of the XML exporter. The only commands of importance in this file in this case are: 

  • <entry key=”vjoon.xmlexporter.plugins”>plugins_WOL.xml</entry>
  • <entry key=”vjoon.xmlexporter.pluginsEnabled”>true</entry>

The first simply provides the name of the plugins file we are using and the second is to say to use the plugin file.

The plugin file is more interesting. The template provided by vjoon is well documented in its comments. I run four plugins. The first is  

<plugin name=”xslt”>
  <attribute name=”xsltfile” value=”/Volumes/Drive2/wolExport2XMLConvertInline.xsl”/>

  <attribute name=”basedir” value=”/Volumes/Drive2/WOLXML/XSLT”/>

This simply states the name and location of the XSLT file. This XSLT converts the raw data from K4 into a format that meets our needs for our future CMS. The goal is to automate transfer of this file to the CMS.

<plugin name=”fileout”>
<attribute name=”dir” value=”/Volumes/Drive2/WOLXML/fileout”/>
<attribute name=”file” value=”wolxslt${d}${n}.xml”/>
<attribute name=”encoding” value=”UTF-8”/>

A simple instruction to write the output to a file in a given location.

The next plugin runs the XSLT wolExport2html.xsl which converts my XML to HTML. And it is followed by another fileout plugin. We did not have to include the first fileout plugin but I wanted to create both versions of the file. Once the new CMS is up we will not run the second XSLT.

Below is the contents of wolExport2XMLconvertInline XSLT with some comments. Comments are in italics

We start with the standard first line.

<?xml version=”1.0” encoding=”UTF-8”?>

Then we need to define the stylesheets to use. The two listed should meet most needs. These include the definitions of the K4 XML tags.


<xsl:stylesheet version=“2.0” xmlns:xsl=“”



Some more standard lines


<xsl:output method=”xml” version=”1.0” encoding=”UTF-8” indent=”no”/>

<xsl:strip-space elements=”*”/>



Look for the article tag and then run the template with the mode of article.


<xsl:template match=”/”>

<xsl:template match=”/”>



<xsl:apply-templates select=”//k4:article” mode=”article”/>






Here is something more interesting. Write the the tag Article and insert the name of the article in the tag. Then add the tag title and insert the same name. Get the contents of the tag section and process, the same with all of the metadata, and then the contents of the article.


<xsl:template match=“k4:article” mode=“article”>


<xsl:attribute name=“title”>

<xsl:value-of select=“lower-case(k4:name)”/>



<!— Place the article name —>


<xsl:value-of select=“lower-case(k4:name)”/>


<!— Process metadata —>
<xsl:apply-templates mode=“section” select=“k4:section”/>
<xsl:apply-templates mode=“metadata” select=“k4:metaData”/>
<!— Process the text objects of each article —>
<xsl:apply-templates mode=“object” select=“k4:textObject”/>





This template finds the name of the section and then asks for the template name.


<xsl:template match=”k4:section” mode=”section”>

<xsl:apply-templates select=”k4:name” mode=”name” />



And then write out the Section tags inserting the section name between them.


<xsl:template match=“k4:name” mode=“name”>

<Section><xsl:apply-templates mode=“name” /></Section>








Get a metadata tag and write a metadata tag with the attribute of the name of the metadata and then the value.

<xsl:template match=“k4:metaData” mode=“metadata”>





<xsl:attribute name=“name”>
<xsl:value-of select=“k4:name”/>
<xsl:apply-templates mode=“string”


The remainder of the XSLT processes the text object following the same logic. The above is not intended to replace reading an XSLT book or 3 but I hope provides a start for someone learning XSLT but has never used it before with K4.