Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Simple Sort

From: "Techno_Dex" <nospamchurst@--------.--->
To: NULL
Date: 5/1/2008 4:08:00 PM

I'm not sure I agree with you on the <xsl:copy> issue as when using the 
<xsl:copy-of> the element is copied as is from the inport node list to the 
output node list and if it were a serializer issue then this would have been 
converted over to contain both the start and end tags as well which is not 
the case.  I am using the simple XslTransform class to perform the 
conversion using the .NET 3.5 framework which by default will use the MSXML 
6 parsing engine which doesn't add an end element tag unless an empty value 
has been added to the node which is what I suspect the xsl:copy function is 
doing.  The attributes on this function don't appear to to contain any 
formating instructions as well to indicate not adding an empty value to the 
element. Is there a way to do a deep copy on the current node() since there 
are no children in order to obtain the desired results?  I'm assuming I 
might have to use a xsl:foreach to obtain this functionality which is not 
very generic.  Am I missing something on the XslTransform perhaps which will 
convert the empty value elements to empty element instead?

            XslTransform xtXslTransform;
            xtXslTransform = new XslTransform();
            xtXslTransform.Load(asXSLTPath);
            xtXslTransform.Transform(asXMLInputPath, asXMLOutputPath);

As for the ordering of my results, you are correct I missed a cut and paste. 
The dates are also not going to be an issue as I will only have at most one 
month of data in the file so the sort order can be done as a simple text 
string without performing the special logic you provided which I thank you 
for as this may come in handy for others.


"Martin Honnen" <mahotrash@y...> wrote in message 
news:OaB%23a$3qIHA.4544@T......
> Techno_Dex wrote:
>
>> I have the following XML file which I want to sort by key then activedate 
>> while maintaining the same order.  I'm trying to generate this is a 
>> generic format so that it can be used for slightly different cases in the 
>> future as well.  I have issues with the xsl:copy creating both a begin 
>> and end element (i.e. <Record></Record>) as opposed to creating an empty 
>> element (i.e <Record />) as well as getting all of the attributes copied 
>> without explicitly identifying them.
>
> Whether an empty element is serialized as e.g. <foo/> or <foo></foo> or 
> <foo /> is a serialization issue and not a question of how xsl:copy works. 
> The XSLT instructions like xsl:copy work on an input tree and a result 
> tree, not on markup. So if you have a 'Record' element marked up as 
> <Record/> in your input document and then use xsl:copy to make a shallow 
> copy to the result tree it does not ensure that the serialization of the 
> result tree later looks the same as input markup. You will have to look 
> into serialization options of your particular XSLT processor if you want 
> to ensure a certain serialization of the result tree.
>
>> <RootElem>
>>     <Record key="2" activedate="04/12/2008 02:00:00" value="Test" 
>> attrib2= "" attrib3="" />
>>     <Record key="1" activedate="04/13/2008 02:00:00" value="Test" 
>> attrib2= "" attrib3="" />
>>     <Record key="5" activedate="04/14/2008 12:00:00" value="Test" 
>> attrib2= "" attrib3="" />
>>     <Record key="3" activedate="04/14/2008 11:00:00" value="Test" 
>> attrib2= "" attrib3="" />
>>     <Record key="87" activedate="04/19/2008 02:30:00" value="Test" 
>> attrib2= "" attrib3="" />
>>     <Record key="64" activedate="04/13/2008 08:00:00" value="Test" 
>> attrib2= "" attrib3="" />
>> </RootElem>
>>
>> Output -> Sorted by key and activedate
>> =======
>> <RootElem>
>>     <Record key="1" activedate="04/13/2008 02:00:00" value="Test" 
>> attrib2= "" attrib3="" />
>>     <Record key="2" activedate="04/12/2008 02:00:00" value="Test" 
>> attrib2= "" attrib3="" />
>>     <Record key="3" activedate="04/14/2008 11:00:00" value="Test" 
>> attrib2= "" attrib3="" />
>>     <Record key="5" activedate="04/14/2008 12:00:00" value="Test" 
>> attrib2= "" attrib3="" />
>>     <Record key="87" activedate="04/19/2008 02:30:00" value="Test" 
>> attrib2= "" attrib3="" />
>>     <Record key="64" activedate="04/13/2008 08:00:00" value="Test" 
>> attrib2= "" attrib3="" />
>> </RootElem>
>
> If you want to first sort on the key and then on the activedate attribute 
> I wonder why key 87 comes before key 64.
> And the date format does not allow sorting unless you reorder it first, 
> the following stylesheet sorts on yyyy-mm-ddThh:mm:ss
>
> <xsl:stylesheet
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   version="1.0">
>
>   <xsl:strip-space elements="*"/>
>
>   <xsl:output method="xml" indent="yes"/>
>
>   <xsl:template match="@* | node()">
>     <xsl:copy>
>       <xsl:apply-templates select="@* | node()"/>
>     </xsl:copy>
>   </xsl:template>
>
>   <xsl:template match="RootElem">
>     <xsl:copy>
>       <xsl:apply-templates select="Record">
>         <xsl:sort select="@key" data-type="number"/>
>         <xsl:sort select="concat(substring(@activedate, 7, 4), '-', 
> substring(@activedate, 1, 2), '-', substring(@activedate, 4, 2), 'T', 
> substring(@activedate, 12))" data-type="text"/>
>       </xsl:apply-templates>
>     </xsl:copy>
>   </xsl:template>
>
> </xsl:stylesheet>
>
>
>
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/ 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent