[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Sorting network addresses

Subject: Re: Sorting network addresses
From: Craig W <codecraig@xxxxxxxxx>
Date: Wed, 2 Mar 2005 08:44:44 -0500
network addresses
Hmm...I must have gotten some stuff mixed up when pasting into the
email... Here is the XML, and XSLT exactly as I have it.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE networks [
<!ELEMENT networks (network+)>
<!ELEMENT network (address)>
<!ELEMENT address (#PCDATA)>
]>
<networks>
	<network>
		<address>1.1.1.1</address>
	</network>
	<network>
		<address>170.5.2.4</address>
	</network>
	<network>
		<address>2.3.1.2</address>
	</network>
</networks>


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
	<xsl:strip-space elements="*" />
	<xsl:variable name="newline">
		<xsl:text>
</xsl:text>
	</xsl:variable>

	<xsl:template match="/">
		<xsl:value-of select="$newline" />
		<networks>
		<xsl:value-of select="$newline" />
				<xsl:for-each select="networks/network">
					<xsl:sort data-type="number" select="substring-before(address,'.')"/>
					<xsl:sort data-type="number"
select="substring-before(substring-after(address,'.'),'.')"/>
					<xsl:sort data-type="number"
select="substring-before(substring-after(substring-after(address,'.'),'.'),'.')"/>
					<xsl:sort data-type="number"
select="substring-after(substring-after(substring-after(address,'.'),'.'),'.')"/>
						<network>
							<xsl:value-of select="$newline" />	
							<address>
								<xsl:value-of select="address" />
							</address>
							<xsl:value-of select="$newline" />
						</network>
						<xsl:value-of select="$newline" />
				</xsl:for-each>
		</networks>
	</xsl:template>
</xsl:stylesheet>


and here is the output

<?xml version="1.0" encoding="UTF-8"?>
		<networks>
		<network>
		<address>1.1.1.1</address>
		</network>
		<network>
		<address>1.1.1.1</address>
		</network>
		<network>
		<address>1.1.1.1</address>
		</network>
		<network>
		<address>1.1.1.1</address>
		</network>
		<network>
		<address>2.3.1.2</address>
		</network>
		<network>
		<address>170.5.2.4</address>
		</network>
		<network>
		<address>2.3.1.2</address>
		</network>
		<network>
		<address>2.3.1.2</address>
		</network>
		<network>
		<address>2.3.1.2</address>
		</network>
		<network>
		<address>170.5.2.4</address>
		</network>
		<network>
		<address>170.5.2.4</address>
		</network>
		<network>
		<address>170.5.2.4</address>
		</network>
		</networks>


I am using XMLSpy to generate the output.  To repeat how I did it,
open the XML document, go to the "XSL/XQuery" menu and choose "XSL
Transformation", point it to the XSLT and thats it.


....now do u get what i get?

thanks

On Wed, 2 Mar 2005 13:33:22 GMT, David Carlisle <davidc@xxxxxxxxx> wrote:
> 
> 
> > the result i am getting now is like this
> Not from upur posted code, you can't: it generates srcaddr elements
> there can't be any address elements in the output.
> 
> Running your posted stylesheet on your posted input I get:
> 
> $ saxon ip.xml ip.xsl
> <?xml version="1.0" encoding="UTF-8"?>
>                 <networks>
>                 <network>
>                 <srcaddr>1.1.1.1</srcaddr>
>                 </network>
>                 <network>
>                 <srcaddr>2.3.1.2</srcaddr>
>                 </network>
>                 <network>
>                 <srcaddr>170.5.2.4</srcaddr>
>                 </network>
>                 </networks>
> 
> Note by the way your $newline is actually a newline and two tabs, hence
> the strange indentaion in the result.
> 
> David
> 
> ________________________________________________________________________
> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> ________________________________________________________________________
> 
> 


-- 

http://www.codecraig.com
http://jroller.com/page/codecraig

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.