-
Notifications
You must be signed in to change notification settings - Fork 19
XSL Templates
Ximdex is based on XML (eXtensible Markup Language). This language consists of a set of rules used to planning and producing structured text files.
Its main advantage is that it is a simple format, standard, extensible, besides not being tied to any private company, platform or programming language, making it ideal as a tool for communication and interoperability. XML is already widely used language that is a first step on the road to the ideal of the semantic web.
As HTML, XML language is based on tags or labels, that is, words in angle brackets ( < and > ), and attributes of the form:
name = "value"
But while in HTML each tag and attribute define a closed behavior, often associated with the appearance to be presented in a browser, XML uses the tags only to enter data, leaving the interpretation of the data to the application that is using the file.
Thus, for example, a label
in an XML file does not have to be necessarily a paragraph, it could be a price, a parameter, etc.. Another distinctive feature is that there is discrimination XML is case sensitive, i.e. <price> element differs from another <Price>.XML element means each of the pieces of information that make up an XML document, and has the general format:
<element attribute1=”value1” attribute2=”value2”>... content ...</element>
We explain in detail each of its parts:
- Tags: They must always be enclosed in angle brackets ('<' and '>') and always specify the closing tag, with the possibility of using an abbreviated syntax if the element has no content:
<element attribute2="value2" attribute1="value1"/>
As a recommendation, the name chosen for the labels should be descriptive enough to easily identify the purpose of the item.
- Properties or attributes: They are additional information that is added to the XML element in its opening tag, always with the format attribute = "value", being obligatory quotes. You can add as many attributes as necessary.
- Content: It is what it is bounded between the start and end labels of the XML element. In the simplest case is just unstructured text, but can also include other elements, and can reach a recursive hierarchical structure, which is what characterizes the XML language.
Finally, note that for considering a well-formed XML, there needs to be a single parent node that is the root of the whole structure.
The structure of the Ximdex Project Manager allows to work with several and independent projects. Each of them has a templates folder (XSL templates) and common to the different servers contained in each project. These templates are stored in the folder ximptd. To become more familiar with the Ximdex interface, please read the Ximdex's interface description here.
Also, a server node defined on our project can contain different levels (or sections) where sorting and organizing information, as hierarchical directories of a filesystem.
[Image1]
Each of these levels contains a folder with XML documents (the ximdoc folder), where Ximdex stores your documents and another folder where you store your own XSL templates only for that level (called ximptd too).
RNG visualization schemas are stored in the folder ximpvd that is unique for each project. This folder contains XML files that define the structure of our documents. We will have as many as different documents we manage in our portal.
The Ximdex transformation engine is responsible for process and convert XML documents contained in Ximdex, generating an output in the format selected by the user. For that task, Ximdex uses these XSL transformation templates specified within the document level or, alternatively, in the main ximptd folder of the project.
Ximdex manages XML documents optimally preparing for its future transformations. Therefore, to begin the process of transformation (whether to render the document in the XML editor for publication or production servers), Ximdex adds a unique label at the beginning of the XML document and some additional attributes to our content. This label is the label <docxap>.
For example, the <docxap> label could be:
<docxap idioma="es" tipo_documento="rng-mi-documento.xml" nodeid = '46004'
parentnodeid = '46003' proyecto="Mi_Proyecto" servido r="myserver.com" documento="index"
nombre_documento="Inicio del portal" canal="" canales="web" canales_desc="Web">
<!-- mi documento XML-->
</docxap>
The additional benefit of adding this label is that we can stop worrying XML document format that we are creating. As discussed in section 1.2 of this document, the XML schema requires that there be a parent node and unique to each document to be considered well-formed XML. The label will act as <docxap> as parent node of all our documents in Ximdex.
To view our label attached document that we just have to access the path <XIMDEX_HOME> / data / nodes /, where <XIMDEX_HOME> represents the path where you have installed on your machine Ximdex. In that directory will find the very structure of our project in Ximdex overturned the file system and all files structured (which we store in the folder ximdoc) are labeled <docxap> added.
Before commenting on the document transformation process conducted in Ximdex, let's consider template_include.xsl file.
This template simply contains a list of all existing XSL templates in the section to which it belongs. It aims to unite the inclusion of all XSL that exist in that section and that may be involved in the transformation.
Your content could be something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:include href="parrafo.xsl"/>
<xsl:include href="lista.xsl"/>
...
</xsl:stylesheet>
His generation is automatic whenever climbed a XSL template section, so we should not worry about keeping it.
This template is referenced in the template docxap.xsl (not to be confused with the label <docxap>) as follows:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:include href="http://myserver.com/<Ximdex_Home>/data/nodes/ruta/a/ximptd/templates_include.xsl"/>
<xsl:template name="docxap" match="docxap">
</xsl:template>
</xsl:stylesheet>
The basic logic that follows the Ximdex transformation engine when processing an XML document and apply the templates is:
-
The XML document starts reading from the beginning, sequentially. The first label or root element is always , so the first team to run will docxap.xsl. This is the only fixed label Ximdex driving, leaving the rest of the user's choice.
-
Finding an XML tag search engine an XSL template in the folder ximptd the same level as the document with the same name as the element found. If not found, look in the folder common ximptd project.
-
Once located the template processing, the output engine replaces the contents of the XML tag for the content of the template transformation.
-
This process is repeated recursively until the treatment end of the XML document.
A channel is the result of the transformation of an XML document to a specified output format. For each channel associated with the XML document, Ximdex generate a different document with the extension specified in the channel. This allows us to obtain different type files such as: html, jsp, pdf, txt, xml or php as a result of the transformation of XML. For our XSL transformation can change depending on the channel, change the attribute Ximdex channel docxap the main label. That is, for a given document and N-channel N Ximdex create XML documents that contain the tag docxap the channel attribute specifying the expected output format. In addition, the label adds an attribute docxap main channels with the list of available channels in the system, separated by commas.
Transformation templates or XSL's are used by Ximdex transformation engine to convert XML documents starting in pre-departure or preset channel by users within Ximdex. Processing templates are themselves XML documents always have the following scheme:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="my_template" match="my_template">
<!-- MY_TEMPLATE CONTENT -->
</xsl:template>
</xsl:stylesheet>
Where my_template represents the XSL template name being edited.
We assume that each element (ie, label) to transform the XML document corresponds to an XSL template. The name of the files processing templates provided must match the name of the XML elements to transform over the. Xsl. Thus, the label will be transformed by XSL parrafo.xsl call and its contents will be:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="parrafo" match="parrafo">
<!-- CONTENIDO DE LA PLANTILLA PARRAFO -->
</xsl:template>
</xsl:stylesheet>
The XML tag attributes are used as modifiers when building a template, ie intervene in the process of generation can make the transformation template act in different ways depending on their values. The way to access these properties is using the syntax @ attribute. Later programming with structures need to use this syntax to create different processing flows as document properties. A simple example might be, given the following XML element:
<paragraph class=”boldie”> Lorem ipsum dolor sit amet</paragraph>
donde la etiqueta tiene un atributo clase cuyo valor es negrita. Si este documento se transformase a HTML, según lo definido en su plantilla de transformación XSL, probablemente su salida sería:
<p class=”bold”> Lorem ipsum dolor sit amet</p>
It has become a label
HTML element and attribute class has been translated into a CSS class called bold. The template can also detect if there is no class attribute and assign the default paragraph style, or even invoke a special template in that case. All this will be discussed later in the programming structures. The content of these templates will always be subject to consistent or output channel that is transforming. It is the case, for example, a printing focused channel should not receive pictures or menus that could be our site, and to print a document that we only need the content itself.
When we want to continue the execution of the templates corresponding to the current internal elements that we are processing is need to indicate to the processor automatically continue without stop and eat the other labels you are. For example, if the XML document starting out:
<paragraph>
<list>
<item>
<paragraph>...text...</paragraph>
</item>
<item>
<list>
<item>...item content...</item>
...
</list>
</item>
<item>
<paragraph>...text...</paragraph>
</item>
</list>
</paragraph>
and paragraph templates defined for the list and the item: utside:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="parrafo" match="parrafo">
<p><xsl:apply-templates/></p>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="lista" match="lista">
<ul><xsl:apply-templates/></ul>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="item" match="item">
<li><xsl:apply-templates/></li>
</xsl:template>
</xsl:stylesheet>```
First, parrafo.xsl template execution, to continue with the evaluation of the document would continue with lista.xsl, then item.xsl. Then again with the paragraph, and thus recursively parsed until the end of the document. The XSL tag that does all this is <xsl:apply-templates/>.
The output we would get would be:
``` ...
<p>
<ul>
<i>
<p>texto texto...</p>
</li>
<li>
<ul>
<li>...contenido item...</li>
...
</ul>
</li>
<li>
<p>texto texto...</p>
</li>
</ul>
</p>
...
Macros are Ximdex mechanism that allows referring to specific files within a template and resolve when processing on the host routes. There are two macros: dotdot and pathto. The first lets you refer to a file by name while the second uses as a parameter the numerical identifier of the file (its node ID in Ximdex). Some examples:
<img border="0" src="@@@RMXimdex.dotdot(images/grafico.gif)@@@" />
<script language="JavaScript">
window.open("@@@RMXimdex.pathto(13937)@@@");
</:script>```
At the time of executing the templates macros expressions would be replaced by the names of the corresponding files with a relative path relative to enable locate right from the level of the output XML document to the level at which the file is resource structure Ximdex levels.
### 2.10- auxiliary Templates
They are often used transformation templates that correspond to XML elements, but merely serve to maintain a separate code fragment in a separate module, which improves the overall maintenance code.
A very common use of this feature is to create a separate XSL template necessary JavaScript functions or other CSS styles to be applied to document elements.
```<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="INCLUDE_estilos" match="INCLUDE_estilos">
<link href="@@@RMximdex.dotdot(css/default.css)@@@" rel="stylesheet" type="text/css" media="screen"/>
<style type="text/css">
#menu{position: absolute; left: 0px; top: 0px; height: 100%; z-index: 1;}
#lineaderecha {position: absolute; left: 769px; top: 61px;}
#foto {position: absolute; left: 645px; top: 155px;}
#contenido {position: absolute; left: 170px; top: 90px; width: 599px; height: 310px; z-index: 2;}
...
...
</style>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="INCLUDE_common_functions" match="INCLUDE_common_function">
<script language="JavaScript1.3" type="text/javascript">
<![CDATA[
function my_function(){
...
}
...
]]>
</script>
<script src="@@@RMXimdex.dotdot(common/functions.js)@@@" type="text/javascript" />
</xsl:template>
</xsl:stylesheet>
Then you only need to invoke them by name in the template you wish to use:
<my_plantilla>
...
<xsl:call-template name="INCLUDE_estilos"/>
<xsl:call-template name="INCLUDE_funciones_comunes"/>
...
</my_plantilla>
These templates are also very useful aids when a particular XML tag, depending on the value of one of its attributes, it undergoes various transformations. In this case you can create a different template for each case thereby achieving better code organization.
The following example is based on the distinction between the language of the document as the value of the label attribute <docxap> language. Distinguish English and Spanish as languages in our system, so we will implement a couple of test conditions to know where to continue the flow of transformation.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="xmlcontent"/>
<xsl:include href="http://myserver.com/ximdex/data/nodes/MyProject/ximPTD/templates_include.xsl"/>
<xsl:template name="docxap" match="docxap">
<xsl:if test="ancestor-or-self::*[@lang][1]/@lang = 'es'">
<xsl:call-template name="docxap-ides"/>
</xsl:if>
<xsl:if test="ancestor-or-self::*[@lang][1]/@lang = 'en'">
<xsl:call-template name="docxap-iden"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>