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

RE: Extracting a list of unique base urls from anchors

Subject: RE: Extracting a list of unique base urls from anchors in a html docu ment.
From: Taras Tielkes <taras@xxxxxxx>
Date: Fri, 14 Sep 2001 13:53:46 +0200
substring before href .
Hi David,

I adopted your earlier suggestion, and used a map:

<xsl:key name="local-links" match="a[contains(@href, '#') and
not(contains(@href, '/'))]" use="substring-before(@href,'#')"/>

The code that uses this map to extract information looks like:

Unique base-urls:
<xsl:for-each select="//a[generate-id() = generate-id(key('local-links',
substring-before(@href, '#'))[1])]">
	href base: <xsl:value-of select="substring-before(@href, '#')"/>
	occurances: <xsl:value-of select="count(key('local-links',
substring-before(@href, '#')))"/> 
</xsl:for-each>	

Can the code above be written in a more efficient way? I guess there isn't a
way to directly iterate over the keys in a map created by <xsl:key>?

By main question, however, is this: how can I aggregate this table of data
into an aggregated one, where every base url part maps to a count of
occurances of this base url part in the source document?


Thanks,
// tt

> -----Original Message-----
> From: David Carlisle [mailto:davidc@xxxxxxxxx]
> Sent: Thursday, September 13, 2001 8:06 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  Extracting a list of unique base urls from 
> anchors in
> a html docu ment.
> 
> 
> 
> > I'm propably wrong,
> 
> I'm afraid so:-)
> 
> > The only difference is that my template doesn't compare the 
> attribute values
> > as-is, but applies a substring before doing so.
> 
> No the string function completely changes the sematics of =.
> 
> If you have an XPath test of the form
> 
> (node-set a) = (node-set b)
> 
> then it is true if _any_ node in set a has a value equal to 
> any node in
> set b.
> 
> That's what you have here:
> 
> @country=preceding-sibling::city/@country
> 
> @country and preceding-sibling::city/@country
> both select node sets.
> 
> If you have
> 
> (string a) = (string b)
> 
> then this is true if the string a equals to the string b.
> 
> that's what you have here:
> 
> substring-before(@href,'#')=substring-before(preceding::a/@href,'#')
> 
> as substring-before always returns a string.
> 
> substring-before requires a string as its first argument and 
> if you give
> it a node set (as here) then it takes the string value of the 
> first node
> (in document order) of the node set.
> 
> @href has at most one node but preceding::a/@href has perhaps 
> many node but
> whatever the current node the first node in that collection 
> is the first
> href attribute on an a element that occurs in the document.
> 
> David
> 
> _____________________________________________________________________
> This message has been checked for all known viruses by Star Internet
> delivered through the MessageLabs Virus Scanning Service. For further
> information visit http://www.star.net.uk/stats.asp or 
> alternatively call
> Star Internet for details on the Virus Scanning Service.
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.