Using XML schema to generate a foreign key type constraint

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have an Xml constraint that I am trying to create an XSD constraint for, but have not been able to yet. As an example:
<ol>
Letâs consider that I have a ticketing system that multiple teams support (and handle tickets for) in different regions.
When a customer reports an issue, it goes to an initial team and could either be serviced by them, or could be redirected to another team in another region (it cannot be redirected to another team in the same region.)
In the case of redirection, I need to ensure that the redirection field of the ticket points to a team with a region different from the region of the team to which this ticket belongs.
</ol>
Sample pertinent xml snippet could look like this:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; Team <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Alpha<span style="color:Black; " <span style="color:Red; Region<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; US<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Tickets<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Ticket <span style="color:Red; Id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 121<span style="color:Black; " <span style="color:Red; Status<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Resolved<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; Ticket <span style="color:Red; Id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 344<span style="color:Black; " <span style="color:Red; Status<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Active<span style="color:Black; " <span style="color:Red; RedirectedTo<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Gamma<span style="color:Black; "<span style="color:Blue; /> <span style="color:Green; <!-- Valid, team in another region -->
<span style="color:Blue; <<span style="color:#A31515; Ticket <span style="color:Red; Id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 984<span style="color:Black; " <span style="color:Red; Status<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Active<span style="color:Black; " <span style="color:Red; RedirectedTo<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Beta<span style="color:Black; "<span style="color:Blue; /> <span style="color:Green; <!-- Invalid, team in the same region (US) -->
<span style="color:Blue; </<span style="color:#A31515; Tickets<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Team<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Team <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Beta<span style="color:Black; " <span style="color:Red; Region<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; US<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; Team <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Gamma<span style="color:Black; " <span style="color:Red; Region<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; CN<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; Team <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Delta<span style="color:Black; " <span style="color:Red; Region<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; AU<span style="color:Black; "<span style="color:Blue; />
[/code]
In the XSD, I can use key/keyref by creating a key for Team Names, and establishing keyref in RedirectedTo. However, I cannot figure out how to ensure that RedirectedTo is not set to a team in the same region.
Is there a way to accomplish this via XSD? Or should I look XSLT or XQuery for more complex rules like this?

View the full article
 
Back
Top