The XPath "@direction"
will test for the presence of a direction
attribute on the current element:
<alternative test="@direction" type="DirectionType"/>
The XPath "not(@direction)"
will test for the absence of a direction
attribute on the current element:
<alternative test="not(@direction)" type="NoDirectionType"/>
Note also that the alternative/@test
attribute can be omitted altogether to provide a default type.
<alternative type="DefaultType"/>
Update to address CTA subset mode per OP's follow-up question
So this <alternative test="@direction='a_value' and not(@another_attribute)"/>
is correct and would make it right?
Yes, but be aware that your XSD processor may use the XPath CTA (Conditional Type Assignment) subset by default. (Xerces, and therefore most Xerces-based tools, do this, for example.) If this is the case, you will get an error that looks something like this:
c-cta-xpath: The XPath expression 'not(@direction)' couldn't compile
successfully in 'cta-subset' mode, during CTA evaluation.
c-cta-xpath: The XPath expression '@direction='a_value' and
not(@another_attribute)' couldn't compile successfully in 'cta-subset'
mode, during CTA evaluation.
To use full XPath 2.0 rather than the CTA subset, configure your tool accordingly. For example, for Xerces, set the following feature to 'true':
http://apache.org/xml/features/validation/cta-full-xpath-checking
In oXygen, there's a checkbox in Options > Preferences > XML > XML Parser > XML Schema
that will control the value of the feature for you.
Using full XPath 2.0, yes, you can use and
in the manner you suggest in your comment.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…