Re: Sorting XML

Giuseppe Fanuzzi wrote:
> 
> Hi people!
> Someone knows how sorting no alphabeticly and no
> numberly a list of XML data using XSL?

You need to do a kind of "join" with a list of possible values that can
be embedded in the stylesheet itself.
 
> Example:
> I would sorting the follow list
> Major, Minor and Open_issue
> 
> in this specific order:
> Major, Open_issue, Minor
> 
> How does it work?

Can be something like:

====GiUSEpPe.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="GiUSEpPe.xslt"?>
<issues>
	<issue>Major</issue>
	<issue>Minor</issue>
	<issue>Open_issue</issue>
</issues>

====GiUSEpPe.xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:g="http://4xt.org/ns/GiUSEpPe" exclude-result-prefixes="g">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:variable name="issues"
select="document('')/xsl:stylesheet/g:issues"/>
	
	<g:issues >
		<issue>Major</issue>
		<issue>Open_issue</issue>
		<issue>Minor</issue>
	</g:issues>
	
	<xsl:template match="/">
		<ul>
			<xsl:apply-templates select="/issues/issue">
				<xsl:sort data-type="number"
select="count($issues/issue[.=current()]/preceding-sibling::*)"/>
			</xsl:apply-templates>
		</ul>
	</xsl:template>
	
	<xsl:template match="issue">
		<li>
			<xsl:value-of select="."/> 
				<xsl:comment> 
					position=<xsl:value-of
select="count($issues/issue[.=current()]/preceding-sibling::*)"/> 
				</xsl:comment>
			</li>
	</xsl:template>
</xsl:stylesheet>

====result:
<?xml version="1.0" encoding="utf-8"?>
<ul>
<li>Major<!--
                                        position=0-->
</li>
<li>Open_issue<!--
                                        position=1-->
</li>
<li>Minor<!--
                                        position=2-->
</li>
</ul>

Eric

> Thanks
> 
-- 
------------------------------------------------------------------------
Eric van der Vlist       Dyomedea                    http://dyomedea.com
http://xmlfr.org         http://4xt.org              http://ducotede.com
------------------------------------------------------------------------

Received on Monday, 11 December 2000 02:39:38 UTC