MMD/XSLT customization questions

This question is mainly directed at Fletcher but if anybody else knows anything about XSLT I’d appreciate an opinion. :slight_smile:

I’m working on a custom version of the 6x9book.xslt that will simulate the \newscene behaviour of sffms (since memoir doesn’t recognize that command) among other small tweaks that I did by hand to make it more appropriate for fiction. This discussion started in bug hunt, but I think it more properly belongs here now.

I have it inserting the centered # at the top of every scene. Having that at the top of a chapter looks goofy, however, so I’ve been trying to figure out a way of suppressing the # if a scene is the first one in a chapter. As near as I can tell, this isn’t possible because the MMD & XHTML source that creates all of this doesn’t actually nest the h2 & h3 elements that indicate titles, so the XML parser doesn’t know it should reset its numbering of h3 every time an h2 pops up. (I did get it to suppress the # on the first scene of the first chapter, but all other chapters had the # at the beginning still.)

Fletcher, have you looked at this at all? Am I reading my sources correctly? Is what I’m attempting possible?

Once I have this sorted out to my satisfaction, I’ll write it up for the tips & tricks, and provide my modified xslt file (which I’ve been calling 6x9novel to distinguish it from the 6x9book).

I found this: … d5280e1102 which appears to be related to what I want to do, but I’m still trying to puzzle out how to apply it.

Have a look at this little one that I wrote: memoir-synopsis.xslt. I think it basically does what you are trying to do. Specifically the second match where it has to detect that another header is opened after the initial abstract header. This would be much more simple, though. Probably something like:

<xsl:template match="h3[preceding-sibling::h2|blockquote]">

…would do the trick? The blockquote bit in there is in case you have an epigraph after the chapter, because in that case the preceding sibling of the first section would be a blockquote element instead of an h2 element. I didn’t check my syntax on that, if it doesn’t work, try:

<xsl:template match="h3[preceding-sibling::h2]|h3[preceding-sibling::blockquote]">

And of course, if none of this works right, Fletcher might have something more insightful to say. I’m still tripping along when it comes to these types of matching cases.

Well, it turned out to be:

<xsl:if test="local-name(preceding-sibling::*[1])='h2'">

I tried the code you posted, but it turns out that preceding-sibling is actually the set of all siblings preceding the current node, and therefore for every h3 there is a preceding sibling somewhere that is an h2.

The code above takes the sibling immediately preceding the current node (*[1]), and figures out what kind it is. If it’s an h2, then I have the first scene in a chapter; if it’s a p, then I have a scene break within a chapter.

I’m still thinking about how to handle epigraphs though - simply checking to see if the preceding-sibling is a blockquote doesn’t account for a blockquote at the very end of a scene. Maybe checking for both preceding siblings [1] and [2], and if they are h2 and blockquote, respectively, then I have an epigraph.