ONYX - 9.0 - Utilisation - Traitements XSL/en

Différence entre versions

De MappingDoc
(Page créée avec « #Filter information #Sort table rows #Manage widows and orphans (line blocks that must be on the same page) #Add information to simplify design #Convert date formats »)
(Page créée avec « <u>XML generated (showing only Article groups for improved readability)</u>: »)
 
(26 révisions intermédiaires par le même utilisateur non affichées)
Ligne 25 : Ligne 25 :
 
#Convert date formats
 
#Convert date formats
  
==Appels==
+
==Calls==
  
Il existe 2 façons d'appeler les feuilles XSL :
+
There are two ways to call XSLT sheets:
  
 
===Workflow===
 
===Workflow===
  
Pour appeler le XSL dans le moteur de règles Mapping (Workflow), il faut utiliser une boite Workflow de type CMD et appeler le programme M-XSLTransform en utilisant la commande suivante :
+
To use XSL Transformation from the Mapping rules engine (Workflow), you need to use a CMD box and call the M-XSLTransform program using the command below:
  [%PATH_BIN%]/M-XSLTransform "[%MAP_FILE_IN%]" "[%PATH_XSL%]/MaFeuilleXSL.xsl" "[%MAP_FILE_OUT%]"
+
  [%PATH_BIN%]/M-XSLTransform "[%MAP_FILE_IN%]" "[%PATH_XSL%]/MyXSLsheet.xsl" "[%MAP_FILE_OUT%]"
<u>Liste des variables</u> :<br>
+
<u>Supported variables</u>:<br>
- '''PATH_BIN''' : chemin du répertoire des binaires Mapping. (Répertoire Applications sur Onyx Windows ou Bin sur Onyx Linux)<br>
+
- '''PATH_BIN''': path to the folder containing Mapping binaries (Applications folder under Onyx Windows or Bin under Onyx Linux)<br>
- '''PATH_XSL''' : chemin du répertoire contenant les feuilles XSL.<br>
+
- '''PATH_XSL''': path to the folder containing XSL sheets<br>
- '''MAP_FILE_IN''' : chemin + nom du fichier d'entrée de la "boite" du workflow <br>
+
- '''MAP_FILE_IN''': path + name of the infile specified in the workflow's box<br>
- '''MAP_FILE_OUT''' : chemin + nom du fichier de sortie de la "boite" du workflow<br>
+
- '''MAP_FILE_OUT''': path + name of the outfile specified in the workflow's box<br>
  
 
===Designer===
 
===Designer===
  
Il est également possible d'appeler des feuilles de transformation XSL directement dans Designer. Le gros avantage par rapport aux appels dans le Workflow est l'aspect intégration native dans Designer. En effet, la feuille XSL permet de personnaliser le document (tri sur les lignes, suppression de lignes, ajout de ligne, gestion des veuves et orphelines, etc.) et fait alors partie intégrante du projet Designer
+
XSL Transformation sheets can also be called directly from within Designer. The advantage over using the Workflow is the native integration in Designer as the XSL sheet helps to customize the document (sorting lines, deleting lines, adding lines, managing widows and orphans, etc.) and is fully integrated into the Designer template.
  
Pour ce faire, il faut saisir le contenu de la feuille XSL dans la fenêtre de saisie accessible via le bouton '''Prétraitement XML''' de Designer encapsulé par '''#xsltransform;''' et '''#endxsltransform;'''
+
To do this, copy and paste the content of the XSLT sheet into the '''XML Pre-processing''' window in Designer between the '''#xsltransform;''' and '''#endxsltransform;''' tags
  
<u>Syntaxe</u> :<br>
+
<u>Syntax</u>:<br>
 
<nowiki>#xsltransform;</nowiki><br>
 
<nowiki>#xsltransform;</nowiki><br>
//''Contenu de la feuille de XSL''<br>
+
//''XSLT sheet content''<br>
 
<nowiki>#endxsltransform;</nowiki>
 
<nowiki>#endxsltransform;</nowiki>
  
Ligne 53 : Ligne 53 :
 
[[Fichier:OX D XLS 1.jpg|vignette|450x450px|alt=|néant]]
 
[[Fichier:OX D XLS 1.jpg|vignette|450x450px|alt=|néant]]
  
==Exemples de feuilles de style XSL==
+
==Sample XSLT Sheets==
Etant donné que nous partons généralement d'un flux XMLDRAW vers un autre flux XMLDRAW, il est possible de créer des exemples de templates XSL ayant chacun une ou plusieurs fonctionnalités bien spécifiques :
+
As we usually transform an XMLDRAW file into another XMLDRAW file, you can create sample XSLT templates with specific functionality:
  
Pour structurer la suite de cette documentation, nous allons partir d'un exemple simple recopiant simplement le flux d'entrée. Dans les exemples qui suivront, nous allons mettre en avant les différences par rapport à cet exemple "coquille générique" afin d'arriver aux résultats souhaités.
+
The content below is based on a simple input data stream. Different examples highlight the differences with the "generic shell" that explain how the expected results are produced.
  
===Coquille générique : Simple copie du flux d'entrée===
+
===Generic shell - Simple copy of the input datastream===
Cet exemple n'a pas de fonction en tant que telle (car il n'est pas utile d'appliquer un traitement XSL si on applique aucune modification aux flux de données) mais sera utilisé par tous les autres exemples qui suivront comme flux générique commun à tous les exemples.
+
This example has no function in itself (because there is no point in applying an XSL transformation process if no change is made to the data stream) but will be used in all subsequent examples as the generic data stream.
  
 
  <span style="color:green"><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
 
  <span style="color:green"><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
Ligne 71 : Ligne 71 :
 
  <span style="color:green"></xsl:stylesheet></span>
 
  <span style="color:green"></xsl:stylesheet></span>
  
<u>Bon à savoir :</u><br>
+
<u>Hint:</u><br>
<span style="color:green">Entete de la feuille XSL</span><br>
+
<span style="color:green">XSL sheet header</span><br>
<span style="color:red">template de simple recopie</span>
+
<span style="color:red">Simple copy template</span>
  
===Supprimer des types de ligne dans un groupe===
+
===Deleting lines from a group===
  
Cet exemple permet de supprimer les types de lignes '''info_remise''' et '''info_compo''' de tous les groupes '''article''' du document.
+
This example deletes the lines of type '''info_remise''' and '''info_compo''' from all '''article''' groups in the document.
  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
Ligne 92 : Ligne 92 :
 
  </xsl:stylesheet>
 
  </xsl:stylesheet>
  
===Ajouter une première ligne et une dernière ligne dans un groupe===
+
===Adding a first and last line to a group===
====Sur tous les groupes====
+
====In all groups====
Cet exemple permet d'ajouter une ligne de début (first_line) et une ligne de fin (last_line) sur tous les groupes du flux d'entrée.
+
This example adds a start line (first_line) and an end line (last_line) to all groups in the input file.
  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
Ligne 114 : Ligne 114 :
 
  </xsl:stylesheet>
 
  </xsl:stylesheet>
  
====Sur un groupe spécifique : Article====
+
====In a specific group - Article====
Cet exemple permet d'ajouter une ligne de début (first_line) et une ligne de fin (last_line) uniquement sur le ou les groupes Article du flux d'entrée.
+
This example adds a start line (first_line) and an end line (last_line) only to the Article group(s) of the file.
  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
Ligne 134 : Ligne 134 :
 
  </xsl:stylesheet>
 
  </xsl:stylesheet>
  
===Supprimer tous les groupes : group1===
+
===Deleting all groups: group1===
  
Cet exemple permet de supprimer tous les groupes group1 (présents sous /doc/page) du flux d'entrée.
+
This example deletes all group1 groups (found in /doc/page) from the file.
  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
Ligne 149 : Ligne 149 :
 
  </xsl:stylesheet>
 
  </xsl:stylesheet>
  
===Trier les lignes du groupe group1 par ordre décroissant===
+
===Sorting the lines of group1 groups in descending order===
  
Cet exemple permet de trier toutes les lignes du groupe group1 du flux d'entrée par ordre décroissant de valeur de l'attribut name.
+
This example sorts all the lines in group1 in descending order based on the ''name'' attribute
  
<u>Feuille XSL</u> :
+
<u>XSLT sheet</u>:
  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  
Ligne 174 : Ligne 174 :
 
  </xsl:stylesheet>
 
  </xsl:stylesheet>
  
<u>Exemple de XML en entrée :</u>
+
<u>Sample input XML file :</u>
  
 
  <doc>
 
  <doc>
Ligne 207 : Ligne 207 :
 
  </doc>
 
  </doc>
  
<u>Flux généré en sortie</u> :
+
<u>Generated output data stream</u>:
  
 
  <?xml version="1.0" encoding="utf-8"?>
 
  <?xml version="1.0" encoding="utf-8"?>
Ligne 240 : Ligne 240 :
 
  </doc>
 
  </doc>
  
===Tri, réagencement, regroupement de lignes===
+
===Sorting, rearranging, grouping lines===
  
Cet exemple permet de :<br>
+
This example:<br>
<span style="color:red"> - Trier les lignes info_livraison des groupes Article par ordre alphabétique croissant de valeur du champs Date_LivConf<br></span>
+
<span style="color:red"> - Sorts info_livraison lines in Article groups in alphabetical ascending order based on the Date_LivConf field<br></span>
<span style="color:green"> - Afficher les autres lignes du groupe Article dans un certain ordre : Info_livraison puis info_article puis info_remise puis info_compo et en dernier toutes les lignes commençant par la valeur tailles<br></span>
+
<span style="color:green"> - Shows the other lines in the Article group in a given order: Info_livraison, then info_article, then info_remise, then info_compo and finally all lines starting with a size value<br></span>
<span style="color:orange"> - Ecrire la ligne info_livraison uniquement si la valeur de son champ date_LivConf est différent de la ligne info_livraison précédente<br></span>
+
<span style="color:orange"> - Writes the info_livraison line only if the value of its date_LivConf field is different from the previous info_livraison line<br></span>
  
<u>Feuille XSL :</u>
+
<u>XSLT sheet:</u>
  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  version="2.0" exclude-result-  
 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  version="2.0" exclude-result-  
Ligne 299 : Ligne 299 :
  
  
<u>Exemple de XML en entrée (uniquement les groupes Article pour simplifier la lisibilité du document)</u> :
+
<u>Sample input XML file (showing only Article groups to improve readability)</u>:
  
 
  <group name="Article">
 
  <group name="Article">
Ligne 305 : Ligne 305 :
 
   <field name="Date_LivDem">2ème Qz Septembre 2014</field>
 
   <field name="Date_LivDem">2ème Qz Septembre 2014</field>
 
   <field name="Sem_LivDem">39</field>
 
   <field name="Sem_LivDem">39</field>
     <span style="color:red"><field name="Date_LivConf">'''20181020'''</field>                  //la ligne de ce champs sera triée par valeur de Date_LivConf</span>
+
     <span style="color:red"><field name="Date_LivConf">'''20181020'''</field>                  //this line is sorted by Date_LivConf</span>
 
   <field name="Sem_LivConf">39</field>
 
   <field name="Sem_LivConf">39</field>
 
   </line>
 
   </line>
Ligne 312 : Ligne 312 :
 
   <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 
   <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 
   </line>
 
   </line>
   <span style="color:green">//Ces 2 lignes seront interverties car le template XSL fait afficher la ligne info_remise avant la ligne
+
   <span style="color:green">//the 2 lines are in reverse order as the XSL template shows info_remise before
 
  info_compo</span>
 
  info_compo</span>
 
   <span style="color:green"><line name="info_compo">
 
   <span style="color:green"><line name="info_compo">
Ligne 327 : Ligne 327 :
 
  </group>
 
  </group>
 
  <group name="Article">
 
  <group name="Article">
  <span style="color:orange">//Cette ligne ne sera pas affichée car la valeur de Date_LivConf de la ligne info_livraison précédente est la même
+
  <span style="color:orange">//this line is not displayed as the value of Date_LivConf in the previous info_livraison line is the same
 
  (20181020)
 
  (20181020)
 
   <line name="info_livraison">
 
   <line name="info_livraison">
Ligne 339 : Ligne 339 :
 
   <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 
   <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 
   </line>
 
   </line>
   <span style="color:green">//Ces 2 lignes seront interverties car le template XSL fait afficher la ligne info_remise avant la ligne
+
   <span style="color:green">//the 2 lines are in reverse order as the XSL template shows info_remise before
 
  info_compo</span>
 
  info_compo</span>
 
   <span style="color:green"><line name="info_compo">
 
   <span style="color:green"><line name="info_compo">
Ligne 357 : Ligne 357 :
 
   <field name="Date_LivDem">2ème Qz Septembre 2014</field>
 
   <field name="Date_LivDem">2ème Qz Septembre 2014</field>
 
   <field name="Sem_LivDem">39</field>
 
   <field name="Sem_LivDem">39</field>
     <span style="color:red"><field name="Date_LivConf">20190101</field>                  //la ligne de ce champs sera triée par valeur de
+
     <span style="color:red"><field name="Date_LivConf">20190101</field>                  //this line is sorted by Date_LivConf</span>
Date_LivConf</span>
 
 
   <field name="Sem_LivConf">39</field>
 
   <field name="Sem_LivConf">39</field>
 
   </line>
 
   </line>
Ligne 378 : Ligne 377 :
 
   <field name="Date_LivDem">2ème Qz Septembre 2014</field>
 
   <field name="Date_LivDem">2ème Qz Septembre 2014</field>
 
   <field name="Sem_LivDem">39</field>
 
   <field name="Sem_LivDem">39</field>
   <span style="color:red"><field name="Date_LivConf">20160101</field>                  //la ligne de ce champs sera triée par valeur de
+
   <span style="color:red"><field name="Date_LivConf">20160101</field>                  //this line is sorted by Date_LivConf</span>
Date_LivConf</span>
 
 
   <field name="Sem_LivConf">39</field>
 
   <field name="Sem_LivConf">39</field>
 
   </line>   
 
   </line>   
Ligne 403 : Ligne 401 :
  
  
<u>XML généré (uniquement les groupes Article pour simplifier la lisibilité du document)</u> :
+
<u>XML generated (showing only Article groups for improved readability)</u>:
  
 
  <group name="Article">
 
  <group name="Article">

Version actuelle datée du 11 décembre 2019 à 15:19

Autres langues :
English • ‎français

Introduction

This page covers the basic principles of XSLT (eXtensible Stylesheet Language Transformations). Mapping will not support XSLT files developed by its users (customers or partners).

Principles

Mapping Onyx introduces support for XSLT so the user can edit the structure of an XML file.


The transformations can be called directly and natively from within Designer, or natively from the rules engine using a specific box in a Workflow.

This feature is new in Onyx and enables the user to modify an XMLDRAW data stream (see details below in Benefits).

Benefits

The main benefit of this new feature is the ability to process a generic input data stream while keeping a customized output data stream.

You can easily edit the input data stream processed by Mapping without making any changes to the program it is generated from. For any given document, you can (among others):

  1. Filter information
  2. Sort table rows
  3. Manage widows and orphans (line blocks that must be on the same page)
  4. Add information to simplify design
  5. Convert date formats

Calls

There are two ways to call XSLT sheets:

Workflow

To use XSL Transformation from the Mapping rules engine (Workflow), you need to use a CMD box and call the M-XSLTransform program using the command below:

[%PATH_BIN%]/M-XSLTransform "[%MAP_FILE_IN%]" "[%PATH_XSL%]/MyXSLsheet.xsl" "[%MAP_FILE_OUT%]"

Supported variables:
- PATH_BIN: path to the folder containing Mapping binaries (Applications folder under Onyx Windows or Bin under Onyx Linux)
- PATH_XSL: path to the folder containing XSL sheets
- MAP_FILE_IN: path + name of the infile specified in the workflow's box
- MAP_FILE_OUT: path + name of the outfile specified in the workflow's box

Designer

XSL Transformation sheets can also be called directly from within Designer. The advantage over using the Workflow is the native integration in Designer as the XSL sheet helps to customize the document (sorting lines, deleting lines, adding lines, managing widows and orphans, etc.) and is fully integrated into the Designer template.

To do this, copy and paste the content of the XSLT sheet into the XML Pre-processing window in Designer between the #xsltransform; and #endxsltransform; tags

Syntax:
#xsltransform;
//XSLT sheet content
#endxsltransform;


Sample XSLT Sheets

As we usually transform an XMLDRAW file into another XMLDRAW file, you can create sample XSLT templates with specific functionality:

The content below is based on a simple input data stream. Different examples highlight the differences with the "generic shell" that explain how the expected results are produced.

Generic shell - Simple copy of the input datastream

This example has no function in itself (because there is no point in applying an XSL transformation process if no change is made to the data stream) but will be used in all subsequent examples as the generic data stream.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0" exclude-result-prefixes="xsl fo xs 
fn">
<xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="no" cdata-section-elements="field"/>
<xsl:template match="@*|*|comment()">
 <xsl:copy>
  <xsl:apply-templates select="@*|*|text()|comment()|processing-instruction()"/>
 </xsl:copy>
</xsl:stylesheet>

Hint:
XSL sheet header
Simple copy template

Deleting lines from a group

This example deletes the lines of type info_remise and info_compo from all article groups in the document.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0" exclude-result-prefixes="xsl fo xs 
fn">
 <xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="no" cdata-section-elements="field"/>
 <xsl:template match="/doc/page/group[@name='Article']/line[@name='info_remise']"/> 
 <xsl:template match="/doc/page/group[@name='Article']/line[@name='info_compo']"/> 
 <xsl:template match="@*|*|comment()">
  <xsl:copy>
   <xsl:apply-templates select="@*|*|text()|comment()|processing-instruction()"/>
  </xsl:copy>
 </xsl:template>
</xsl:stylesheet>

Adding a first and last line to a group

In all groups

This example adds a start line (first_line) and an end line (last_line) to all groups in the input file.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0" exclude-result-prefixes="xsl fo xs fn">
 <xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="no" cdata-section-elements="field"/>
 <xsl:template match="group">
       <xsl:copy>
           <xsl:apply-templates select="@*"/>
           <line name="first_line"/>
           <xsl:apply-templates/>
           <line name="last_line"/>
       </xsl:copy>
 </xsl:template> 
 <xsl:template match="@*|*|comment()">
     <xsl:copy>
       <xsl:apply-templates select="@*|*|text()|comment()|processing-instruction()"/>
     </xsl:copy>
 </xsl:template>
</xsl:stylesheet>

In a specific group - Article

This example adds a start line (first_line) and an end line (last_line) only to the Article group(s) of the file.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0" exclude-result-prefixes="xsl fo xs fn">
<xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="no" cdata-section-elements="field"/>
 <xsl:template match="group[@name='Article']">
       <group name="Article">
           <line name="first_line"/>
           <xsl:apply-templates/>
           <line name="last_line"/>
       </group>
   </xsl:template>
   <xsl:template match="@*|*|comment()">
     <xsl:copy>
      <xsl:apply-templates select="@*|*|text()|comment()|processing-instruction()"/>
     </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

Deleting all groups: group1

This example deletes all group1 groups (found in /doc/page) from the file.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0" exclude-result-prefixes="xsl fo xs fn">
<xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="no" cdata-section-elements="field"/>
<xsl:template match="/doc/page/group[@name='group1']"/> 
   <xsl:template match="@*|*|comment()">
     <xsl:copy>
      <xsl:apply-templates select="@*|*|text()|comment()|processing-instruction()"/>
     </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

Sorting the lines of group1 groups in descending order

This example sorts all the lines in group1 in descending order based on the name attribute

XSLT sheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0" exclude-result-prefixes="xsl fo xs 
fn">
<xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="no" cdata-section-elements="field"/>
<xsl:template match="/doc/page/group[@name='group1']">
 <xsl:copy>
  <xsl:apply-templates select="@*"/>
    <xsl:apply-templates>
     <xsl:sort select="./@name" data-type="text" order="descending"/>
  </xsl:apply-templates>
 </xsl:copy>
 </xsl:template> 
   <xsl:template match="@*|*|comment()">
     <xsl:copy>
      <xsl:apply-templates select="@*|*|text()|comment()|processing-instruction()"/>
     </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

Sample input XML file :

<doc>
<page>
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
<group name="group1">
<line name="line1">
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
</line>
<line name="line2">
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
</line>
<line name="line3">
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
</line>
</group>
<group name="group2">
<line name="line1">
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
</line>
<line name="line2">
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
</line>
</group>
</page>
</doc>

Generated output data stream:

<?xml version="1.0" encoding="utf-8"?>
<doc>
<page>
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
<group name="group1">
<line name="line3">
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
</line>
<line name="line2">
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
</line>
<line name="line1">
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
</line>
</group>
<group name="group2">
<line name="line1">
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
</line>
<line name="line2">
<field name="field1">ValueField1</field>
<field name="field2">ValueField2</field>
</line>
</page>
</doc>

Sorting, rearranging, grouping lines

This example:
- Sorts info_livraison lines in Article groups in alphabetical ascending order based on the Date_LivConf field
- Shows the other lines in the Article group in a given order: Info_livraison, then info_article, then info_remise, then info_compo and finally all lines starting with a size value
- Writes the info_livraison line only if the value of its date_LivConf field is different from the previous info_livraison line

XSLT sheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"  version="2.0" exclude-result- 
prefixes="xsl xs">
 <xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="no" cdata-section-elements="field"/>
  <xsl:template match="/doc/page">
   <page>
    <xsl:apply-templates select="*[not(self::group[@name='Article'])]"/>
    <xsl:apply-templates select="group[@name='Article']">
     <xsl:sort select="line[@name='info_livraison']/field[@name='Date_LivConf']" data-type="text" order="ascending"/>
    </xsl:apply-templates>
   </page>
  </xsl:template>
  <xsl:template match="group[@name='Article']">
   <group name="Article">			
     <xsl:if test="not(preceding-sibling::group[@name='Article']/line[@name='info_livraison']/field[@name='Date_LivConf'] = 
./line[@name='info_livraison']/field[@name='Date_LivConf'])">
      <xsl:apply-templates select="./line[@name='info_livraison']"/>
    </xsl:if>
    <xsl:apply-templates select="./line[@name='info_article']"/>
    <xsl:apply-templates select="./line[@name='info_remise']"/>
    <xsl:apply-templates select="./line[@name='info_compo']"/>
    <xsl:apply-templates select="./line[starts-with(@name, 'tailles')]">
    <xsl:sort select="@name" data-type="text" order="ascending"/>
    </xsl:apply-templates>
   </group>
  </xsl:template>
  <xsl:template match="@*|*|comment()">
   <xsl:copy>
    <xsl:apply-templates select="@*|*|text()|comment()|processing-instruction()"/>
   </xsl:copy>
  </xsl:template>
</xsl:stylesheet>


Sample input XML file (showing only Article groups to improve readability):

<group name="Article">
 <line name="info_livraison">
  <field name="Date_LivDem">2ème Qz Septembre 2014</field>
  <field name="Sem_LivDem">39</field>
   <field name="Date_LivConf">20181020</field>                   //this line is sorted by Date_LivConf
  <field name="Sem_LivConf">39</field>
 </line>
 <line name="info_article">
  <field name="Reference">HOLDEN734</field>
  <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 </line>
 //the 2 lines are in reverse order as the XSL template shows info_remise before
info_compo
  <line name="info_compo">
  <field name="Composition"><![CDATA[98% Polyester-2% Coton]]></field>
 </line>
 <line name="info_remise">
  <field name="Remise_Totale_Ligne">5</field>
 </line>
 <line name="tailles_1">
  <field name="Qte">20</field>
  <field name="Unt_Oeuvre">U</field>
  <field name="Lib_Unt_Oeuvre"><![CDATA[Unité(s)]]></field>
 </line>
</group>
<group name="Article">
//this line is not displayed as the value of Date_LivConf in the previous info_livraison line is the same
(20181020)
 <line name="info_livraison">
  <field name="Date_LivDem">2ème Qz Septembre 2014</field>
  <field name="Sem_LivDem">39</field>
  <field name="Date_LivConf">20181020</field>
  <field name="Sem_LivConf">39</field>
 </line>
 <line name="info_article">
  <field name="Reference">HOLDEN734</field>
  <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 </line>
 //the 2 lines are in reverse order as the XSL template shows info_remise before
info_compo
 <line name="info_compo">
  <field name="Composition"><![CDATA[98% Polyester-2% Coton]]></field>
 </line>
 <line name="info_remise">
  <field name="Remise_Totale_Ligne">5,5</field>
 </line>
 <line name="tailles_1">
  <field name="Qte">20</field>
  <field name="Unt_Oeuvre">U</field>
  <field name="Lib_Unt_Oeuvre"><![CDATA[Unité(s)]]></field>
 </line>
</group>
<group name="Article">
 <line name="info_livraison">
  <field name="Date_LivDem">2ème Qz Septembre 2014</field>
  <field name="Sem_LivDem">39</field>
   <field name="Date_LivConf">20190101</field>                   //this line is sorted by Date_LivConf
  <field name="Sem_LivConf">39</field>
 </line>
 <line name="info_article">
  <field name="Reference">HOLDEN734</field>
  <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 </line>
 <line name="info_compo">
  <field name="Composition"><![CDATA[98% Polyester-2% Coton]]></field>
 </line>
 <line name="tailles_1">
  <field name="Qte">20</field>
  <field name="Unt_Oeuvre">U</field>
  <field name="Lib_Unt_Oeuvre"><![CDATA[Unité(s)]]></field>
 </line>
</group>
<group name="Article">
 <line name="info_livraison">
  <field name="Date_LivDem">2ème Qz Septembre 2014</field>
  <field name="Sem_LivDem">39</field>
  <field name="Date_LivConf">20160101</field>                   //this line is sorted by Date_LivConf
  <field name="Sem_LivConf">39</field>
 </line>  
 <line name="info_article">
  <field name="Reference">HOLDEN734</field>
  <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 </line>
 <line name="info_compo">
  <field name="Composition"><![CDATA[98% Polyester-2% Coton]]></field>
 </line>
 <line name="tailles_1">
  <field name="Qte">20</field>
  <field name="Unt_Oeuvre">U</field>
  <field name="Lib_Unt_Oeuvre"><![CDATA[Unité(s)]]></field>
 </line>
 <line name="tailles_2">
  <field name="Qte">2</field>
  <field name="Unt_Oeuvre">U</field>
  <field name="Lib_Unt_Oeuvre"><![CDATA[Unité(s)]]></field>
 </line>
</group>


XML generated (showing only Article groups for improved readability):

<group name="Article">
 <line name="info_livraison">
  <field name="Date_LivDem"><![CDATA[2ème Qz Septembre 2014]]></field>
  <field name="Sem_LivDem"><![CDATA[39]]></field>
   <field name="Date_LivConf"><![CDATA[20160101]]></field>
  <field name="Sem_LivConf"><![CDATA[39]]></field>
 </line>
 <line name="info_article">
  <field name="Reference"><![CDATA[HOLDEN734]]></field>
  <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 </line>
 <line name="info_compo">
  <field name="Composition"><![CDATA[98% Polyester-2% Coton]]></field>
 </line>
 <line name="tailles_1">
  <field name="Qte"><![CDATA[20]]></field>
  <field name="Unt_Oeuvre"><![CDATA[U]]></field>
  <field name="Lib_Unt_Oeuvre"><![CDATA[Unité(s)]]></field>
 </line>
 <line name="tailles_2">
  <field name="Qte"><![CDATA[2]]></field>
  <field name="Unt_Oeuvre"><![CDATA[U]]></field>
  <field name="Lib_Unt_Oeuvre"><![CDATA[Unité(s)]]></field>
 </line>
</group>
<group name="Article">
 <line name="info_livraison">
  <field name="Date_LivDem"><![CDATA[2ème Qz Septembre 2014]]></field>
  <field name="Sem_LivDem"><![CDATA[39]]></field>
   <field name="Date_LivConf"><![CDATA[20181020]]></field>
  <field name="Sem_LivConf"><![CDATA[39]]></field>
 </line>
 <line name="info_article">
  <field name="Reference"><![CDATA[HOLDEN734]]></field>
  <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 </line>
 <line name="info_remise"><field name="Remise_Totale_Ligne"><![CDATA[5]]></field>
 </line>
 <line name="info_compo">
  <field name="Composition"><![CDATA[98% Polyester-2% Coton]]></field>
 </line>
 <line name="tailles_1">
  <field name="Qte"><![CDATA[20]]></field>
  <field name="Unt_Oeuvre"><![CDATA[U]]></field>
  <field name="Lib_Unt_Oeuvre"><![CDATA[Unité(s)]]></field>
 </line>
</group>
<group name="Article">
 <line name="info_article">
  <field name="Reference"><![CDATA[HOLDEN734]]></field>
  <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 </line>
 <line name="info_remise">
  <field name="Remise_Totale_Ligne"><![CDATA[5,5]]></field>
 </line>
 <line name="info_compo">
  <field name="Composition"><![CDATA[98% Polyester-2% Coton]]></field>
 </line>
 <line name="tailles_1">
  <field name="Qte"><![CDATA[20]]></field>
  <field name="Unt_Oeuvre"><![CDATA[U]]></field>
  <field name="Lib_Unt_Oeuvre"><![CDATA[Unité(s)]]></field>
 </line>
</group>
<group name="Article">
 <line name="info_livraison">
  <field name="Date_LivDem"><![CDATA[2ème Qz Septembre 2014]]></field>
  <field name="Sem_LivDem"><![CDATA[39]]></field>
   <field name="Date_LivConf"><![CDATA[20190101]]></field>
  <field name="Sem_LivConf"><![CDATA[39]]></field>
 </line>
 <line name="info_article">
  <field name="Reference"><![CDATA[HOLDEN734]]></field>
  <field name="Designation"><![CDATA[HOLDEN Blanc]]></field>
 </line>
 <line name="info_compo">
  <field name="Composition"><![CDATA[98% Polyester-2% Coton]]></field>
 </line>
 <line name="tailles_1">
  <field name="Qte"><![CDATA[20]]></field>
  <field name="Unt_Oeuvre"><![CDATA[U]]></field>
  <field name="Lib_Unt_Oeuvre"><![CDATA[Unité(s)]]></field>
 </line>
</group>