Re: Validating application-specific XHTML

Hi,

I would hate to see a schema that validates a CSS based XHTML page.  
Even worse, I would hate to maintain it.

However, it would be pretty easy to use an XSL to validate your page.  
You could base the XSL off of your CSS rules. For example, you might  
have a CSS containing:

#narrow-col #nav { blah... }
#wide-col .article { blah... }

An XSL might look like:


<xsl:key name="ident" match="*" use="@id"/>

<xsl:template match="/">
   <ol>
     <li>
       <xsl:apply-templates select="." mode="validate-nav"/>
     </li>
     <li>
       <xsl:apply-templates select="." mode="validate-content"/>
     </li>
etc...
   </ol>
</xsl:template>

<xsl:template match="*" mode="validate-nav">
   <p>
     Has Nav:
     <xsl:value-of select="exists(key('ident', 'narrow-col')/ 
*[@id='nav'])"/>
   </p>
</xsl:template>

<xsl:template match="*" mode="validate-content">
   <p>
     Has at least one content piece:
     <xsl:value-of select="exists(key('ident', 'wide-col')/ 
*[@class='article'])"/>
   </p>
</xsl:template>

best,
-Rob



On Nov 26, 2008, at 12:56 PM, Michael Ludwig wrote:

>
> I'm using XSLT to produce XHTML, or at least XML that approaches  
> XHTML.
>
> I'd like a way to guarantee the correctness of this markup.
>
> It's not correctness in terms of "-//W3C//DTD XHTML 1.0 Strict//EN"  
> that
> I have in mind here. That can be done using the DTD.
>
> It's correctness in terms of the markup specific to my application. To
> give an example, it always has a menu that can be modelled in terms of
> XSD. And an entry in a search result list always is a <div> containing
> certain attributes, certain elements, etc.
>
> In my schema, I'd have, say, a "MenuType", and a "ListType", and an
> "ItemType", and so on. The page will be decomposed in terms of types,
> as can be done using XML Schema.
>
> The main purpose of this validation to counter-check my hacking away  
> at
> the XSLT and to ensure the result doesn't fall out of sync with the  
> CSS.
> A sort of regression test.
>
> This may then be used in conjunction with HttpUnit (a Java library to
> test web applications) to serve as a quality assurance robot.
>
> As I'm far from being a seasoned XML Schema user, I'd like to hear
> any feedback the members of this list might have on the feasability,
> shortcomings, blind spots or other aspects of this attempt.
>
> Do you know of any useful libraries or technologies that might support
> me in my endeavour?
>
> And probably someone has done this before?
>
> Thank you very much.
>
> Michael Ludwig
>
>

Received on Wednesday, 26 November 2008 22:26:36 UTC