RE: [xsl] Wrap HTML headings and following siblings in <section/>

Subject: RE: [xsl] Wrap HTML headings and following siblings in <section/>
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 27 Mar 2010 11:13:25 -0000
> Currently processors choke on the XPath,
> 
> (html:h1|html:h2|html:h3|html:h4|html:h5|html:h6)/following-si
bling::node()

That's a legal XPath 2.0 expression, but it's not legal in 1.0. You have to
write

*[self::h1|self::h2|...]/following-sibling::node()

Though it's probably more efficient to do

*[preceding-sibling::*[self::h1|self::h2|self::h3...]]

Looking at your code, you're trying to use this as an XSLT pattern rather
than as an XPath expression. For a pattern, you need to use this last form
whether you're in 1.0 or 2.0.

Overall, I think this kind of problem is much better tackled using sibling
recursion, where you apply-templates to the first sibling, it does
apply-templates to the next sibling, and so on. Or in 2.0, you can use
<xsl:for-each-group group-starting-with="h1"/>.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

Current Thread