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

Re: More XPath 1.0 Expression help

Subject: Re: More XPath 1.0 Expression help
From: Todd Ditchendorf <itod@xxxxxxxxx>
Date: Wed, 19 Jul 2006 14:52:26 -0700
xml exists duplicate xsltproc
Thanks Mike and Spencer, that definitely got me going in the right direction!

However, I don't think I have XSLT grouping available to me in this case... let me explain.

This XPath is to be used in a Schematron <sch:asstert> test attribute. I am using the XSLT ref impl of Schematron 1.5 running against libxslt witch is limited to XSLT 1.0 and XPath 1.0. I don't think i can access exslt from the schematron schema ,so exslt is out.

Also, I'm assuming that I cannot access XSLT grouping mechanisms from within the schematron schema, so that, unfortunately, is out too. : ( Please correct me if I'm wrong there.

So here's what i've got so far:



	<sch:pattern name="Report Duplicate Keys">
		<sch:rule context="/plist/dict/key">
			<sch:assert test="count(../key[.=current()]) = 1">
					Duplicate '<sch:value-of select="."/>' key exists
					<sch:value-of select="count(../key[.=current()])"/> times.
					Keys should be unique.</sch:assert>
		</sch:rule>
	</sch:pattern>


So I have access to the XSLT current() func but no XSLT grouping features AFAIK. This rule gets the job of detecting duplicate keys done... unfortunately it also raises n errors for n duplicate keys rather than just one error for n duplicate keys. That's certainly not a show-stopper... but it would be nice to fix.


Any ideas?

The O(n^2) complexity doesn't bother me in this instance as perf is not a prime concern here and the data set is very small anyway.

Here's what the actual input looks like... it's an Apple plist:

<plist>
<dict>
<key>Key1</key>
<value/>
<key>Key2</key>
<value/>
<key>Key3</key>
<value/>
<key>Key1</key>
<value/>
</dict>
</plist>


Todd



On Jul 19, 2006, at 2:22 PM, Michael Kay wrote:


Take a look at http://www.jenitennison.com/xslt/grouping

Most of the techniques for grouping are at the XSLT level, but you can use
the basic


key[not(. = preceding-sibling::key)]

if you don't mind O(n^2) complexity.

This detects the distinct values: leave out the not() and you have an
expression that detects the duplicates.

Michael Kay
http://www.saxonica.com/


-----Original Message----- From: Todd Ditchendorf [mailto:itod@xxxxxxxxx] Sent: 19 July 2006 22:18 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: More XPath 1.0 Expression help


I need some help constructing an XPath to detect nodes containing duplicate string-values. I am currently restricted to XPath 1.0 syntax , so no access to distinct-values() or exslt unfortunately.

I have a document like this:

<dict>
<key>Key1</key>
<value/>
<key>Key2</key>
<value/>
<key>Key3</key>
<value/>
<key>Key1</key>
<value/>
</dict>

How do I create an XPath 1.0 expression to detect the <key>
elements with duplicate string-values?


Thanks!



Todd Ditchendorf Software Engineer itod@xxxxxxxxx

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.