On Thu, May 10, 2012 at 8:27 PM, Richard Heck <rgh...@comcast.net> wrote:
> On 05/10/2012 04:52 PM, Nico Williams wrote:
>> On Thu, May 10, 2012 at 3:31 PM, Richard Heck<rgh...@comcast.net>  wrote:
>> Here's a LyX snippet:
>
> OK, I see the problem. The vertical space gets moved, for reasons
> that probably aren't very interesting. Can you file a bug about this on
> trac? I can fix it, but it will take a little thought about how best to do
> it.

Filed http://www.lyx.org/trac/ticket/8154

Thanks.

>> FYI, right now I'm struggling with how to transform h2, h3, h4
>> elements into nested section elements; [...]
>>
> It could be done in LyX, but I guess I'd suggest pre-processing the
> whole thing with some kind of script. It shouldn't be too hard to do.
> Find h1, write a start tag; when you see another h1, write the end tag
> for the first one; etc.

I've figured out how to handle this with XSLT 2.0.  Here's a snippet:

<xsl:template match="h2">
    <xsl:element name="section">
        <xsl:attribute name="title">
            <!-- XXX Remove the section numbering added by LyX -->
            <xsl:value-of select="normalize-space(.)"/>
        </xsl:attribute>

        <!-- Some variables needed to help select sub-sets of following
             siblings -->
        <xsl:variable name="num-siblings" select="count(following-sibling::*)"/>
        <xsl:variable name="next-hN"
            select="((following-sibling::*[name() = 'h2' or name() =
'h3' or name() = 'h4']) |
            following-sibling::*[$num-siblings])[1]"/>
        <xsl:variable name="end-hN"
            select="((following-sibling::h2) |
            following-sibling::*[$num-siblings])[1]"/>

        <!-- Handle the contents of this section -->
        <xsl:apply-templates select="following-sibling::*[. &lt;&lt;
$next-hN]"/>

        <!-- Handle sub-sections of this section -->
        <xsl:apply-templates select="following-sibling::h3[. &lt;&lt;
$end-hN]"/>
    </xsl:element>
</xsl:template>

The key is the << operator (here encoded, so &lt;&lt;).  The right
operand had to be stored in a variable because there's no other way
(that I could find!) to refer to the node I wanted to there.

That took a lot of effort to work out.  Much more than I'd wanted to.
And it requires XSLT 2.0.  But it works and it's not terribly
inelegant -- more elegant than any robust script to do the same, most
likely.

>> [I'm guessing that LyX's XHTML output is not stable, but I can cope,
>> provided I find a way to transform those h elements into nested
>> sections.]
>>
> It's generally stable, but of course under development. Mostly, I want
> it to be as modular and customizable as possible, in which case we can
> all make it do what we want.

Great.  Thanks so much for your work and your help!

Nico
--

Reply via email to