Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Help sorting xml to xml

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 10/6/2009 1:14:00 PM
derekmw wrote:

> <a>
> 	<b>
> 		<c type="period">
> 			<key>
> 				<d name="date">2006-09-12 00:00:00.0</d>
> 			</key>
> 			...(many other elements, many which have nested elements 6-7 levels
> deep)
> 		</c>
> 		<c type="period">
> 			<key>
> 				<d name="date">2006-09-15 00:00:00.0</d>
> 			</key>
> 			...(many other elements, many which have nested elements 6-7 levels
> deep)
> 		</c>
> 	</b>
> </a>
> 
> From what I read/understood, with xsl, you have to specify all the
> fields you want to copy over to the new xml transformation?  If so,
> that's just not an option as there are so many other elements within
> the 'c' elements I want to sort by.
> 
> What I need to do is find a quick way to sort the 'c' elements by the
> 'd' element value (date).  Any suggestions/direction would be
> appreciated!

With XSLT 1.0 you can put xsl:sort elements as children of the 
xsl:for-each or xsl:apply-templates elements. What you do then is up to 
you thus if you want to sort and then make a deep copy that is certainly 
possible e.g.

   <xsl:template match="b">
    <xsl:copy>
     <xsl:for-each select="c">
       <xsl:sort select="key/d[@name = 'date']"/>
       <xsl:copy-of select="."/>
     </xsl:for-each>
    </xsl:copy>
   </xsl:template>

So the above is a template for 'b' elements that makes a shallow copy of 
the 'b' element and then processes the 'c' children, sorted by the text 
value of the "key/d[@name = 'date']" grandchild element and then simply 
makes a deep copy.


-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/


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