Subject: Re: [xsl] More XPath 1.0 Expression help From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Wed, 19 Jul 2006 18:22:51 -0400 |
Oh well, Wendell
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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] More XPath 1.0 Expression, Michael Kay | Thread | Re: [xsl] More XPath 1.0 Expression, Todd Ditchendorf |
RE: [xsl] More XPath 1.0 Expression, Michael Kay | Date | Re: [xsl] Lookup, eliminating dupli, Dimitre Novatchev |
Month |