character before first child node and after last child node in xslt



I have the following xml:



<line>
<orig><hi>W</hi>e be <gap quantity="4" unit="chars" reason="illegible"/>ed and moeued of <gap quantity="6" unit="chars" reason="illegible"/></orig>
</line>


I'd like to apply some styling to it such that every time there is a sequence of nodes in a row, the first gap node is prefaced with a left square bracket and the last node is followed by a right square bracket. A number of dots, taken from the @quantity element in , will be displayed for each gap node So, for example, the xml above should look like this:


We be [....]ed and moeued of [......]


I've written a template that adds the bracket before the first node and after the last node, so it looks like this:


We be [....ed and moeued of ......]


My xslt code is here:



<xsl:template match="tei:orig/tei:gap">
<xsl:variable name="max" select="@quantity"/>
<xsl:if test="not(preceding-sibling::tei:gap)">
<xsl:text>[</xsl:text>
</xsl:if>
<xsl:for-each select="1 to $max">
<xsl:text>.</xsl:text>
</xsl:for-each>
<xsl:if test="not(following-sibling::tei:gap)">
<xsl:text>]</xsl:text>
</xsl:if>
</xsl:template>


How would I handle the other brackets? I thought I might be able to do it by writing a template that applies to the node directly by stepping up a level and using position(), but that just wraps each set of dots in square brackets instead of only wrapping the beginning and ending of each sequence of nodes.


No comments:

Post a Comment