RE: [xsl] Sort Question

Subject: RE: [xsl] Sort Question
From: omprakash.v@xxxxxxxxxxxxx
Date: Tue, 7 Jun 2005 11:24:37 +0530
Hi,

   Sorry for the delay. Please use the following xsl to achieve what you
want.


<?xml version="1.0" encoding="ISO-8859-1"?>
<?altova_sps C:\Documents and Settings\simonj\My
Documents\us101\xml\Messages.sps?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:xalan
="http://xml.apache.org/xalan";
>
           <xsl:output method="text"/>
           <xsl:strip-space elements="*"/>

           <xsl:param name="file" select=" 'MESSAGES.h' "/>

           <xsl:variable name="assignment" select=" ' = ' "/>
           <xsl:variable name="terminator" select="  ' ;' "/>

           <xsl:template match="dataroot">
                               <xsl:apply-templates select="node()"/>
           </xsl:template>


<!--
-->
<!-- This template matches an Enumerated Type                -->
<!--
-->
<!--           It creates a header for the type and then     -->
<!--           creates the C struct.
-->
<!--
-->

           <xsl:template match="tblEnumeratedTypes_WC" priority="1">
                     <xsl:choose>
                               <xsl:when test="1=position()">
                                          <xsl:call-template name
="SectionHeader">
                                                    <xsl:with-param
name="SectionName" >Enumerated Types</xsl:with-param>
                                          </xsl:call-template>
                               </xsl:when>
                     </xsl:choose>
                     <xsl:apply-templates select="." mode="doc"/>
                     <xsl:apply-templates select="." mode="struct"/>
                     <xsl:apply-templates select="." mode="range-macro"/>
           </xsl:template>


<!--
-->
<!--      This template is used to create the Section Headers
-->
<!--
-->

           <!-- Should Be Centered ?? -->
           <xsl:template name="SectionHeader">
                     <xsl:param name="SectionName"/>

//----------------------------------------------------------------------
----------------

//----------------------------------------------------------------------
----------------
           //        <xsl:value-of select="$SectionName"/>

//----------------------------------------------------------------------
----------------

//----------------------------------------------------------------------
----------------
           </xsl:template>



<!--
-->
<!--      This template creates the header for an enumerated Type
-->
<!--
-->

           <xsl:template match="tblEnumeratedTypes_WC" mode="doc">

//----------------------------------------------------------------------
----------------
           // Name                  : <xsl:apply-templates select
="EnumeratedType"/>
           // Description    : <xsl:apply-templates select="Description"/>


//----------------------------------------------------------------------
----------------
           </xsl:template>




<!--
-->
<!--      This template creates the structure for an enumerated Type
-->
<!--
-->
           <xsl:template match="tblEnumeratedTypes_WC" mode="struct">

           enum {
                               <xsl:apply-templates select
="tblEnumValues_WC">
                                          <xsl:sort select="EnumValue"/>
                               </xsl:apply-templates>
           }   ;
           </xsl:template>

<!--
-->
<!--      This template creates the line for each of the enumerations
within         -->
<!--      an Enumerated Type
-->
<!--
-->

           <xsl:template match="tblEnumValues_WC">
                     <xsl:call-template name="padSpaces">
                               <xsl:with-param name="text" >
                                          <xsl:call-template name
="removeSpaces">
                                                    <xsl:with-param name
="text"
select="EnumValueDescription"/>
                                          </xsl:call-template>
                               </xsl:with-param>
                               <xsl:with-param name="size"
>20</xsl:with-param>
                     </xsl:call-template>

                     <xsl:text> = </xsl:text>

                     <!-- If we are on the last line, dont add a "," or
carriage return -->
                     <xsl:value-of select="EnumValue"/>
                     <xsl:choose>
                               <xsl:when test="last()=position()">
                               </xsl:when>

                               <xsl:otherwise>
                                          <xsl:text>, &#x0a;
</xsl:text>
                               </xsl:otherwise>
                     </xsl:choose>

           </xsl:template>



<!--
-->
<!--      This template creates call to the RANGE_TYPE Macro for an
enumerated Type     -->
<!--
-->

           <xsl:template match="tblEnumeratedTypes_WC" mode="range-macro">

           <xsl:variable name="ET" select="EnumeratedType"/>

          RANGE_TYPE ( UINT8, <xsl:value-of select="$ET"/>,

                     <xsl:apply-templates select="tblEnumValues_WC" mode
="makecopy">
                     <xsl:sort select="EnumValue"/>
                     </xsl:apply-templates>

<!--
                     <xsl:variable name="Start">
                               <xsl:call-template name="removeSpaces">
                                          <xsl:with-param name="text"
select="(xalan:nodeset($vtblEnumValue)//EnumValueDescription)[1]"/>
                               </xsl:call-template>
                     </xsl:variable>
                               <xsl:variable name="End" >
                                          <xsl:call-template  name
="removeSpaces">
                                                    <xsl:with-param name
="text"
select="(xalan:nodeset($vtblEnumValue)//EnumValueDescription)[last()]"/>
                                          </xsl:call-template>
                               </xsl:variable>
           <xsl:variable name="ET" select="EnumeratedType"/>
           RANGE_TYPE ( UINT8, <xsl:value-of select="$ET"/>, <xsl:value-of
select="$Start"/>, <xsl:value-of select="$End"/> ) ;

-->

           </xsl:template>



<xsl:template match="tblEnumValues_WC" mode="makecopy">



<xsl:variable name="lastcheck">
<xsl:if test="last() = 1">
<xsl:value-of select="1"/>
</xsl:if>
</xsl:variable>


<xsl:choose>
<xsl:when test="position() = 1 or $lastcheck = 1">

                     <xsl:variable name="Start">
                               <xsl:call-template  name="removeSpaces">
                                          <xsl:with-param name="text"
select="EnumValueDescription"/>
                               </xsl:call-template>
                     </xsl:variable>

<xsl:value-of select="$Start"/>

<xsl:if test="$lastcheck=1">
);
</xsl:if>



</xsl:when>
<xsl:when test="position() = last()">
 <xsl:variable name="End" >
 <xsl:call-template  name="removeSpaces">
 <xsl:with-param name="text"
          select="EnumValueDescription"/>
 </xsl:call-template>
 </xsl:variable>

, <xsl:value-of select="$End"/>) ;

</xsl:when>
<xsl:otherwise>

</xsl:otherwise>
</xsl:choose>










</xsl:template>



<!--
-->
<!--
-->
<!--
-->


           <xsl:template name="removeSpaces">
                     <xsl:param name="text"/>
                     <xsl:value-of select="translate($text, '&#x20;', ''
)"/>
           </xsl:template>



<!--
-->
<!--
-->
<!--
-->


           <xsl:template name="padSpaces">
                     <xsl:param name="text"/>
                     <xsl:param name="size"/>
                     <xsl:variable name="spaces" select="'
'" />
                     <xsl:value-of select="$text"/>
                     <xsl:choose>
                               <xsl:when test="string-length($text) &lt;
$size">
                                          <xsl:value-of select="substring
($spaces,
1, $size - string-length($text) )"/>
                               </xsl:when>
                     </xsl:choose>
           </xsl:template>

</xsl:stylesheet>


Cheers,
Omprakash.V



This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. 
If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in

Current Thread