<?xml version="1.0" encoding="UTF-8" ?>
<!--
 #  The Contents of this file are made available subject to the terms of
 #  GNU Lesser General Public License Version 2.1
 #
 #  The Initial Developer of the Original Code is :
 #  BOBICIEL INFORMATIQUE - FRANCE, April 2003
 #
 #  Contributor(s):
 #  Robert DARGAUD  BOBICIEL INFORMATIQUE
 #  _______________ ______________________________
 #  _______________ ______________________________
 #  _______________ ______________________________
 #  _______________ ______________________________
 #
 #
 #  GNU Lesser General Public License Version 2.1
 #  =============================================
 #
 #  This library is free software; you can redistribute it and/or
 #  modify it under the terms of the GNU Lesser General Public
 #  License version 2.1, as published by the Free Software Foundation.
 #
 #  This library is distributed in the hope that it will be useful,
 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 #  Lesser General Public License for more details.
 #
 #  You should have received a copy of the GNU Lesser General Public
 #  License along with this library; if not, write to the Free Software
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 #  MA  02111-1307  USA
 #
 #  =============================================
  -->

<!-- Product name : MaXOpenInfo -->
<!-- Version      :  -->
<!-- Date         :  -->

<!--
 -->
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>

	<xsl:key name="ChildsForParentName" match="//*" use="concat(name(../../..),name(../..),name(..))"/>
	<xsl:key name="AttributesForParentName" match="//@*" use="concat(name(../../..),name(../..),name(..))"/>
	<xsl:key name="ChildsForName" match="*" use="concat(name(../../..),name(../..),name(..),name(.))"/>
	<xsl:key name="AttributesForName" match="@*" use="concat(name(../../..),name(../..),name(..),name(.))"/>
	<xsl:key name="isNotNumericValueForAttributeName" match="@*[contains(number(concat(., '0')), 'NaN')]" use="concat(name(../../..),name(../..),name(..),name(.))"/>
	<xsl:key name="isNotPourcentValueForAttributeName" match="@*[contains(number(substring-before(., '%')), 'NaN') or (substring-after(., '%')!='')]" use="concat(name(../../..),name(../..),name(..),name(.))"/>

	<!--  -->
	<xsl:template match="/">
    	<xsl:apply-templates/>
	</xsl:template>

	<!--  -->
	<xsl:template match="*">
       	<xsl:element name="{name(.)}">
            <xsl:for-each select="key('AttributesForParentName', concat(name(../..),name(..),name(.)))[generate-id() = generate-id(key('AttributesForName', concat(name(current()/../..),name(current()/..),name(current()),name(.)))[1])]">
                <xsl:attribute name="{name(.)}">
                	<xsl:value-of select="."/>
                </xsl:attribute>
            </xsl:for-each>
            <xsl:for-each select="key('ChildsForParentName', concat(name(../..),name(..),name(.)))[generate-id() = generate-id(key('ChildsForName', concat(name(current()/../..),name(current()/..),name(current()),name(.)))[1])]">
                <xsl:apply-templates select="."/>
            </xsl:for-each>
       	</xsl:element>
  	</xsl:template>

</xsl:transform>

