Between two anchors


Permalink 10:34:55 pm, by jtakeda, 254 words, 12 views   English (CA)
Categories: Activity log; Mins. worked: 180

Between two anchors

I've been trying to figure out the best way to retrieve all nodes between two anchors; I'm not changing the document hierarchy (i.e. I'm not tagging them), but I want them for labelling purposes etc. But doing following:: and preceding:: or using the following/preceding operators (>>) operators with intersect isn't very efficient.

It's nice because we have @xml:ids on these things, so it's easy enough to know when to stop. It's not generalized for non-id'd things (although, I bet you could use generate-id(.)).

<xsl:function name="hcmc:betweenTwoAnchors" as="node()*"> <xsl:param name="anchor1" as="node()"/> <xsl:param name="anchor2" as="element(anchor)"/> <xsl:variable name="f1" select="$anchor1/following::node()[1]" as="node()"/> <xsl:variable name="f2" select="$f1/following::node()[1]" as="node()?"/> <xsl:copy-of select="$f1"/> <xsl:choose> <xsl:when test="($f2/self::anchor and $f2/@xml:id = $anchor2/@xml:id) or empty($f2)"/> <xsl:otherwise> <xsl:copy-of select="hcmc:betweenTwoAnchors($f1,$anchor2)"/> </xsl:otherwise> </xsl:choose> </xsl:function> <
Basically, it works by taking in two boundary points, using the left one and stepping to the next node; if the node immediately following that one is the anchor tag, then exit; if it's not, run the thing again, but using the next node ($f1). This is all actually documented in the LEMDO code, but thought I should put it here in case.


No Pingbacks for this post yet...


Linked Early Modern Drama Online


XML Feeds