> On 18 Sep 2018, at 22:47, Jim Albright jim_albright@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Using Saxon 9.8.0.12 in Oxygen
> Style sheet version="2.0"
> Problem domain is getting a dictionary created in Word with only <p>s,
<span>s and <b>, and <i> along with some color added to some spans.
> In plain text it looks like:
>
There is far more detail here than I can possible absorb in the time left
before bedtime, but to try and answer your specific question:
> My guess so far is to match the <br/> and then look for <b> words following
but donbt include <b> after <span class="Arial" that turns into \translation
.
>
> <xsl:template match="html:br">
> <xsl:element name="span">
> <xsl:attribute name="class">example</xsl:attribute>
> <xsl:value-of select="following::html:b"/> <<<<<<<<<<<< this
gives too many
> </xsl:element>
> </xsl:template>
>
> I hold the slash code in the class attribute until the last step. That way I
can continue working on the file in XML.
>
> How do I restrict the <xsl:value-of select="following::html:b"/> to just the
ones before the next
> <span class="Arial">I want to go.<br />
>
(1) Firstly, I think you can use following-sibling::html:b rather than
following::html:b, which is a much more contained search.
(2) To stop the search at element X, the best solution in XSLT 3.0 is probably
xsl:iterate
<xsl:iterate select="following-sibling::*">
...
<xsl:if test="self::h:span[@class='Arial']"><xsl:break/></xsl:if>
</xsl:iterate>
xsl:iterate is basically like for-each except the order of processing is
guaranteed and you can therefore break out as soon as a condition is
satisfied; you can also pass data from one iteration to the next via
parameters.
Michael Kay
Saxonica
|