Subject: [xsl] Selecting the first sentence of a paragraph|
From: Larry Kollar <kollar@xxxxxxxxxx>
Date: Mon, 27 Oct 2003 23:13:47 -0500
<section> <label>show exception</label> <p>Syntax: <cmd>show exception <arg>n</arg></cmd></p> <p>Identical to <keyword>systat</keyword>. The optional argument <arg>n</arg> specifies the level of detail.</p> <other>stuff we don't care about</other> </section>
The part I have working pretty well applies the identity transform to the first paragraph if it starts with "Syntax." I also want to copy the first sentence of the next paragraph (or the first sentence of the first paragraph if there's no "Syntax" definition). The following template gets the first sentence but removes the internal markup:
<xsl:template match="p" mode="firstsentence"> <p><xsl:copy-of select='concat(substring-before(.,"."), ".")' /></p> </xsl:template>
Producing "Identical to systat." That I expect, and set it up as a placeholder until I could get what I really wanted. That's been somewhat knottier.
I assume I'll have to use xsl:for-each to select all the nodes up to the first period in the paragraph, apply the identity transform to them, then select the node containing the period and use the concat(substring-before(.,"."),".") function to get that part.
I've tried a couple of variations on xsl:for-each select='./*/preceding-sibling::*[contains(text(),".")]' which is probably causing hysterical laughter and/or retching among some of you.... I'm probably making this harder than it has to be.