[thelist] XPath question

Steve Wainscott swainscott at dicentral.com
Fri Apr 29 10:56:47 CDT 2005


Problem: 

   I need an XPath expression that will return the "CLASS" nodes whose
"priority" attribute is a duplicate for each "ALLOCATION" node in an XML
doc.  In other words, for each "ALLOCATION" node in the document, each
"CLASS" child's priority attribute must be unique.  The goal is to validate
the document with Schematron, which uses XPath to make assertions on the
document.

 

 

*** VALID Example ***   

<ALLOCATION type="CLASS" name="CLASS A">

<CLASS priority="1" name="Highest Priority"> <!-- OK, priority unique -->

            <STORE name="Target A 1
1">7e30db2577a644b9bc26a568c6ddb7d5</STORE>

            <STORE name="Target A 1
2">6e30db2577a644b9bc26a568c6ddb7d5</STORE>

      </CLASS>

      <CLASS priority="2" name="Second Priority"> <!-- OK, priority unique
-->

            <STORE name="Steinmartt A 2
1">6f7ae1a0-47e4-11d9-9669-0800200c9a66</STORE>

            <STORE name="Walmart A 2
2">415ab260-5229-11d9-9669-0800200c9a66</STORE>

      </CLASS>

      <CLASS priority="2" name="Third Priority"> <!-- OK, priority unique
-->

            <STORE name="Marshalls A 3
1">6f7ae1a0-47e4-11d9-9669-0800200c9a66</STORE>

            <STORE name="Home
Depot">6f7ae1a0-47e4-11d9-9669-0800200c9a66</STORE>

      </CLASS>

</ALLOCATION>

 

*** INVALID Example *** 

<ALLOCATION type="CLASS" name="CLASS B">

<CLASS priority="1" name="Highest Priority"> <!-- OK, priority unique -->

            <STORE name="Target A 1
1">7e30db2577a644b9bc26a568c6ddb7d5</STORE>

            <STORE name="Target A 1
2">6e30db2577a644b9bc26a568c6ddb7d5</STORE>

      </CLASS>

      <CLASS priority="2" name="Second Priority"> <!-- OK, priority unique
-->

            <STORE name="Steinmartt A 2
1">6f7ae1a0-47e4-11d9-9669-0800200c9a66</STORE>

            <STORE name="Walmart A 2
2">415ab260-5229-11d9-9669-0800200c9a66</STORE>

      </CLASS>

      <CLASS priority="2" name="Third Priority"> <!-- FAILED, priority not
unique, return node -->

            <STORE name="Marshalls A 3
1">6f7ae1a0-47e4-11d9-9669-0800200c9a66</STORE>

            <STORE name="Home
Depot">6f7ae1a0-47e4-11d9-9669-0800200c9a66</STORE>

      </CLASS>

</ALLOCATION>

 

Steve Wainscott

Software Engineer

DICentral, Corp.

 



More information about the thelist mailing list