Subject: Re: [xsl] Testing implicit XHTML hierarchy From: "bryan rasmussen" <rasmussen.bryan@xxxxxxxxx> Date: Thu, 5 Jul 2007 01:35:35 +0200 |
<xsl:template match="/"> <output> <xsl:variable name="h" select="//xhtml:*[matches(local-name(),'^h[1-6]')]/number(substring(local-name(),2))"/>
<xsl:if test="not($h[1]=1 and count($h[.=1])=1)">h1 not right</xsl:if> <xsl:for-each select="1 to count($h)-1"> <xsl:if test="(($h[.+1][1])-($h[.][1]) > 1) or (($h[.+1][2])-($h[.][2]) > 1)"> section head jumped by more than one level </xsl:if> </xsl:for-each> </output> </xsl:template>
on testing; nope that produces too many "section head jumped by more than one level"
Actually thinking about it the solution is still pretty simple in XSLT 1.0 also, as per:
<xsl:template match="xhtml:*[starts-with(local-name(),'h')][string-length(substring-after(local-name(),'h'))=1]"> <xsl:variable name="headingtype" select="number(substring-after(local-name(),'h'))"/> <xsl:choose> <xsl:when test="number(substring-after(local-name(following::xhtml:*[starts-with(local-name(),'h')][string-length(substring-after(local-name(),'h'))=1][1]),'h'))=$headingtype"/> <xsl:when test="number(substring-after(local-name(following::xhtml:*[starts-with(local-name(),'h')][string-length(substring-after(local-name(),'h'))=1][1]),'h'))=($headingtype + 1)"/><xsl:when test="number(substring-after(local-name(following::xhtml:*[starts-with(local-name(),'h')][string-length(substring-after(local-name(),'h'))=1][1]),'h'))< $headingtype "/> <xsl:when test="not(following::xhtml:*[starts-with(local-name(),'h')][string-length(substring-after(local-name(),'h'))=1])"/> <xsl:otherwise><error>the <xsl:value-of select="number(substring-after(local-name(following::xhtml:*[starts-with(local-name(),'h')][string-length(substring-after(local-name(),'h'))=1][1]),'h'))"/> following <xsl:value-of select="local-name()"/> does not follow the rules <xsl:value-of select="."/></error></xsl:otherwise></xsl:choose> </xsl:template>
<xsl:template match="xhtml:h1" priority="1"> <xsl:if test="following::xhtml:h1"><error>There may be only one h1</error></xsl:if> <xsl:if test="following::xhtml:*[starts-with(local-name(),'h')][string-length(substring-after(local-name(),'h'))=1]"> <xsl:if test="number(substring-after(local-name(following::xhtml:*[starts-with(local-name(),'h')][string-length(substring-after(local-name(),'h'))=1][1]),'h')) != 2"><error>The first heading after h1 must be an h2</error></xsl:if></xsl:if> </xsl:template>
that could be cleaned up a bit of course. But I think it is relatively concise. also have a redundant xsl;if in the xhtml:h1 template, caused by paranoia. :)
Cheers, Bryan Rasmussen
I think you can just do something like
<xsl:variable name="h" select="//xhtml:*[matches(local-name(),'^h[1-6])]/number(substring(local-name(),2))"/>
<xsl:if test="not($h[1]=1 and count($h[.=1])=1)">h1 not right</xsl:if> <xsl:for-each select="1 to count($h)-1"> <xsl:if test="$h[.+1]-$h[.] gt 1"> section head jumped by more than one level </xsl:if>
David
________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Testing implicit XHTML hi, David Carlisle | Thread | Re: [xsl] Testing implicit XHTML hi, David Carlisle |
Re: [xsl] Removing an XML Attribute, Tony Graham | Date | Re: [xsl] Testing implicit XHTML hi, David Carlisle |
Month |