OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Validation question

[ Lists Home | Date Index | Thread Index ]

You can validate this kind of constraint using the Schematron assertion 
language.
See http://www.ascc.net/xml/schematron for information and 
http://www.topologi.com/
for a free Windows validator.   (The following are untested, just to 
give a hint)

Kiia Kallio wrote:

>There are a few problematic things in SVG:
>
>- Some elements (such as "feConvolveMatrix") have a matrix as their parameter. This matrix
>is defined with two attributes: "order" (number-optional-number) and "kernelMatrix" (list
>of numbers). In order for the attributes to be valid, the "kernelMatrix" should have as
>many values as the order defines (for instance order = "3, 2" means that the matrix should
>have 6 values). There are also other cases of cross-dependencies like this.
>  
>
The validation code for this will be quite klunky, but certainly 
possible. The latest version
of Schematron (1.1.6) has a let expression that helps, and I expect 
newer versions based on
XPath 2 will be around soon; these will have features that should 
directly make this
kind of constraint simpler to model. 

<rule context="svg:feConvolveMatrix[@order][@kernelMatrix]"
    <let name="car" value="string-before(@order, ',')" />
    <let name="cdr" value="string-after(@order, ',')" />
    <let name="orderValue" value=" number( $car) * number( $cdr )" />
    <let name="first" value="string-before(@kernelMatrix, ',')" />
     <let name="after-first" value="string-after(@kernelMatrix, ',')" />
    <let name="second" value="string-before( $after-first , ',')" />
     <let name="after-second" value="string-after( $after-first , ',')" />
    <let name="third" value="string-before( $after-second , ',')" />
     <let name="after-third" value="string-after( $after-second , ',')" />
     ...
   <assert test="( $orderValue = 1  and not 
string-contains(@kernelMatrix, ','))
     or (($orderValue &lt; 1 or number(first))
         and (( $orderValue &lt; 2  or number( $second ))
         and (( $orderValue &lt; 3  or number( $third ))
     ... "
     >
    The kernelMatrix should have as many values as the order attribute 
specifies
   </assert>

For some versions of schematron before 1.1.6 you will have to make a single
big fat Xpath for all those things: it will rapidly explode in size.

>- Animation elements ("animate", "set", "animateColor", "animateTransform", "animateMotion")
>have some attributes ("by", "from", "to", "values") that define the new values for the
>animated attribute of some other element. The valid values for the attribute depend on the
>target attribute and the target element that has the attribute. For instance markup
><set xlink:href = "#foobar" attributeName="type" to="turbulence" begin="3s" dur="6s"/>
>is completely valid if the element whose id is "foobar" is "feTurbulence". If it happens
>to be for instance "feColorMatrix", this is not valid. "feColorMatrix" does have "type"
>attribute, but "turbulence" is not a valid value for that. (And it is not even necessary to
>define "xlink:href" attribute to specify the animated element, but if the attribute is
>missing, the animation target is the parent element.
>
<rule context="svg:set">
    <let name="constructedName" value="..XPath to make feTurbulence from 
turbulence" />
    <assert test="//*[name() = $constructedName 
][@id=string-after(current()/@xlink:href, '#')]" />
    The set element's href must point to an element of type <value-of 
select=" $constructed-name" />.
    </assert>
</rule>

>So, I'd like to know if any validation schema can handle such things like cross-
>dependencies of attributes, dependencies between attributes and element types, and
>parsing of complex attributes for validating them, or (as the designers of various
>schemas are probably reading the list) if there are any plans for the features I'm
>looking for.
>
As mentioned, Schematron is good for all these things, with the current 
shortfalling (inherited from XPath1)
that parsing complex attribute values is cumbersome. This should change 
soon with XPath2.

>One option I think would be to construct some sort of XSLT transformation that re-formats
>complex attributes to XML that is easier to validate (like the path example above) but I
>know very little about XSLT, so I don't really know if it can handle things like this. If
>somebody has pointers for cases where this has been succesfully done, I'd be grateful.
>
Look at Simon StLaurent's  "Regular Fragmentations" code for a start.

Cheers
Rick Jelliffe






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS