[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: More XPath 1.0 Expression help
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/
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!
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|