[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Testing implicit XHTML hierarchy

Subject: Re: Testing implicit XHTML hierarchy
From: "bryan rasmussen" <rasmussen.bryan@xxxxxxxxx>
Date: Wed, 4 Jul 2007 22:45:01 +0200
Re:  Testing implicit XHTML hierarchy
oops, obvious mistake in the xpath is the greater than should be greater than 1.


Cheers, Bryan Rasmussen


On 7/4/07, bryan rasmussen <rasmussen.bryan@xxxxxxxxx> wrote:
is the idea though that there can be the following:

h1
 h2
  h3
h1
 h2
 h2

because then what you have doesn't look like it should work. for
example if it is an
h2 and you want the following to be an h2 or h3 you would do something
like this:

following::xhtml:*[starts-with(local-name(),'h')][string-length()=2][(number(substring-after(local-name(),'h'))
&lt; 4) and (number(substring-after(local-name(),'h')) &gt; 2 )][1]

this is probably wrong though, haven't tested. probably you will need
to do some data type checking in the xpath (a guess), so like I said
an initial guess on how it would be done.

Cheers,
Bryan Rasmussen

On 7/4/07, bryan rasmussen <rasmussen.bryan@xxxxxxxxx> wrote:
> Well I find this kind of a weird way of doing it, one thing about
> having a DSL like Schematron is that you have it because it is easier
> to express what you want to do in it rather than in the implementation
> language of the DSL. In this case you are expressing it first in the
> common implementation language, and then moving it to the domain
> specific language.
>
>
> Cheers,
> Bryan Rasmussen
>
>
> On 7/4/07, Jesper Tverskov <jesper@xxxxxxxxxxx> wrote:
> > hi list
> >
> > I want to make XPath expressions later to be transferred from XSLT to
> > Schematron that can validate an implicit XHTML hierarchical structure
> > that is the correct use of heading elements h1-h6       .
> >
> > The rules could be expressed like this:
> >
> > 1.      There can only be one h1, and it must be the first heading.
> > 2.      The first heading after h1 must be h2.
> > 3.      The first heading after h2 must be h2 or h3.
> > 4.      The first heading after h3 must be h2 or h3 or h4.
> > 5.      The first heading after h4 must be h2 or h3 or h4 or h5
> > 6.      The first heading after h5 or h6 can be anything except h1.
> >
> > My expressions in the following XSLT stylesheet work fine. I think. No
> > problem. But I am wondering if there are easier ways to make the
> > expressions or if I have forgotten something.
> >
> > <?xml version="1.0"?>
> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
> >     xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xhtml">
> >     <xsl:output indent="yes"/>
> >     <xsl:template match="/">
> >         <test>
> >             <xsl:apply-templates
> >                 select="xhtml:html/xhtml:body//xhtml:h1 |
> > xhtml:html/xhtml:body//xhtml:h2 | xhtml:html/xhtml:body//xhtml:h3 |
> > xhtml:html/xhtml:body//xhtml:h4"
> >             />
> >         </test>
> >     </xsl:template>
> >
> >     <xsl:template match="xhtml:html/xhtml:body//xhtml:h1">
> >         <xsl:if test="preceding::xhtml:h1">
> >             <error>There can only be one h1</error>
> >         </xsl:if>
> >         <xsl:if
> >             test="preceding::xhtml:h2 or preceding::xhtml:h3 or
> > preceding::xhtml:h4 or preceding::xhtml:h5 or preceding::xhtml:h6">
> >             <error>h1 must be the first heading.</error>
> >         </xsl:if>
> >         <xsl:if
> >             test="following::xhtml:h2 or following::xhtml:h3 or
> > following::xhtml:h4 or following::xhtml:h5 or following::xhtml:h6">
> >             <xsl:if
> >
> > test="not(following::xhtml:h2[1][not(preceding::xhtml:h3)][not(preceding::xhtml:h4)][not(preceding::xhtml:h5)][not(preceding::xhtml:h6)])">
> >                 <error>The first heading after h1 must be h2</error>
> >             </xsl:if>
> >         </xsl:if>
> >     </xsl:template>
> >
> >     <xsl:template match="xhtml:html/xhtml:body//xhtml:h2">
> >         <xsl:if test="following::xhtml:h4[1][preceding::xhtml:h2[1] eq
> > current()]">
> >             <xsl:if
> >
> > test="following::xhtml:h4[1][not(preceding::xhtml:h2[1][preceding::xhtml:h2[1]
> > eq current()])]
> >                     and
> > following::xhtml:h4[1][not(preceding::xhtml:h3[1][preceding::xhtml:h2[1]
> > eq current()])]">
> >                 <error>The first heading after h2 must be h2 or h3</error>
> >             </xsl:if>
> >         </xsl:if>
> >         <xsl:if test="following::xhtml:h5[1][preceding::xhtml:h2[1] eq
> > current()]">
> >             <xsl:if
> >
> > test="following::xhtml:h5[1][not(preceding::xhtml:h2[1][preceding::xhtml:h2[1]
> > eq current()])]
> >                         and
> > following::xhtml:h5[1][not(preceding::xhtml:h3[1][preceding::xhtml:h2[1]
> > eq current()])]">
> >                 <error>The first heading after h2 must be h2 or h3</error>
> >             </xsl:if>
> >         </xsl:if>
> >         <xsl:if test="following::xhtml:h6[1][preceding::xhtml:h2[1] eq
> > current()]">
> >             <xsl:if
> >
> > test="following::xhtml:h6[1][not(preceding::xhtml:h2[1][preceding::xhtml:h2[1]
> > eq current()])]
> >                     and
> > following::xhtml:h6[1][not(preceding::xhtml:h3[1][preceding::xhtml:h2[1]
> > eq current()])]">
> >                 <error>The first heading after h2 must be h2 or h3</error>
> >             </xsl:if>
> >         </xsl:if>
> >     </xsl:template>
> >
> >     <xsl:template match="xhtml:html/xhtml:body//xhtml:h3">
> >         <xsl:if test="following::xhtml:h5[1][preceding::xhtml:h3[1] eq
> > current()]">
> >             <xsl:if
> >
> > test="following::xhtml:h5[1][not(preceding::xhtml:h3[1][preceding::xhtml:h3[1]
> > eq current()])]
> >                     and
> > following::xhtml:h5[1][not(preceding::xhtml:h4[1][preceding::xhtml:h3[1]
> > eq current()])]
> >                     and
> > following::xhtml:h5[1][not(preceding::xhtml:h2[1][preceding::xhtml:h3[1]
> > eq current()])]
> >                     ">
> >                 <error>The first heading after h3 must be h2 or h3 or h4</error>
> >             </xsl:if>
> >         </xsl:if>
> >         <xsl:if test="following::xhtml:h6[1][preceding::xhtml:h3[1] eq
> > current()]">
> >             <xsl:if
> >
> > test="following::xhtml:h6[1][not(preceding::xhtml:h3[1][preceding::xhtml:h3[1]
> > eq current()])]
> >                     and
> > following::xhtml:h6[1][not(preceding::xhtml:h4[1][preceding::xhtml:h3[1]
> > eq current()])]
> >                     and
> > following::xhtml:h5[1][not(preceding::xhtml:h2[1][preceding::xhtml:h3[1]
> > eq current()])]
> >                     ">
> >                 <error>The first heading after h3 must be h2 or h3 or h4</error>
> >             </xsl:if>
> >         </xsl:if>
> >
> >     </xsl:template>
> >
> >     <xsl:template match="xhtml:html/xhtml:body//xhtml:h4">
> >         <xsl:if test="following::xhtml:h6[1][preceding::xhtml:h4[1] eq
> > current()]">
> >             <xsl:if
> >
> > test="following::xhtml:h6[1][not(preceding::xhtml:h4[1][preceding::xhtml:h4[1]
> > eq current()])]
> >                     and
> > following::xhtml:h6[1][not(preceding::xhtml:h5[1][preceding::xhtml:h4[1]
> > eq current()])]
> >                     and
> > following::xhtml:h6[1][not(preceding::xhtml:h2[1][preceding::xhtml:h4[1]
> > eq current()])]
> >                     and
> > following::xhtml:h6[1][not(preceding::xhtml:h3[1][preceding::xhtml:h4[1]
> > eq current()])]
> >                     ">
> >                 <error>The first heading after h4 must be h2 or h3 or
> > h4 or h5</error>
> >             </xsl:if>
> >         </xsl:if>
> >     </xsl:template>
> >
> > </xsl:stylesheet>
> >
> > Cheers,
> > Jesper Tverskov

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.