About using xs:unique on xsi:type in a sequence

前端 未结 2 1921
时光取名叫无心
时光取名叫无心 2021-01-23 17:49

It is possible to have a unique constraint on an element\'s type ?

Let\'s say I have a Noah\'s Ark where Animal/@name must be unique.

Below\'s an XML that do not

2条回答
  •  一整个雨季
    2021-01-23 17:55

    All the implementations I could test on XSD 1.0 seem to agree on one thing here: the identity constraints will be tested only if the selectors/fields match XML nodes for which an associated user defined schema component can be found. xsi:type, while it is a schema related markup, is not considered here since its intention is different. It might prove academically interesting to check if a Schematron assertion might help here...

    UPDATE: I am including the Schematron version, too; I am running the ISO version, XSLT1 w/ Microsoft extensions since I am on .NET.

    
    
        
        
    
       
          
            
            
                Only one-of-a-kind animal is allowed.
            
                Only one-of-a-kind animal is allowed (naive).
          
       
    
    

    I've defined two assertion, a "naive" one that textually compares the value of the xsi:type attribute; and the "correct" one which compares them as QName s.

    For this XML:

      
         
         
         
     
    

    This is the result:

    
    
        
        
        
        
        
            
                Only one-of-a-kind animal is allowed.
        
        
        
            
                Only one-of-a-kind animal is allowed.
        
        
            
                Only one-of-a-kind animal is allowed (naive).
        
        
        
            
                Only one-of-a-kind animal is allowed.
        
        
            
                Only one-of-a-kind animal is allowed (naive).
        
    
    

    As you can see from the failed assertions, the "naive" way is flagging only 2 of 3 instances; again, comparing the value of the xsi:type attribute as text is not the same as comparing QName s (which is what @xsi:types are).

提交回复
热议问题