Re: [xsl] select the word to the left of the current node

Subject: Re: [xsl] select the word to the left of the current node
From: "Terry Ofner tdofner@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 25 Aug 2022 17:21:05 -0000
I think I solved my own problem. In place of group-adjacent I used
group-ending-with: I also had to return "n/a" in groups that contained no
fnTerm so that only groups with fnTerms are selected in the main
choose/when.


<xsl:template match="p[var]">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:variable name="varCount">

                <xsl:value-of select="count(var)"/>

            </xsl:variable>

            <xsl:for-each-group select="*|node()" group-ending-with="var">

                <xsl:variable name="original_id">

                        <xsl:for-each select="current-group()/span/a">
                            <xsl:value-of select=
"substring-after(@href,'#')"/>
                        </xsl:for-each>
                    </xsl:variable>

                    <xsl:variable name="tooltip_text">
                        <xsl:value-of select=
"$footnoteSet/p[@id=$original_id]/text()[1]"/>
                    </xsl:variable>

                    <xsl:variable name="fnTerm">
                        <xsl:choose>

                            <xsl:when test="matches($tooltip_text,'[a-z]')">
                                <xsl:value-of select=
"$footnoteSet/p[@id=$original_id]/@term"/>
                            </xsl:when>

                            <xsl:otherwise>

                                <xsl:text>n/a</xsl:text>

                            </xsl:otherwise>

                        </xsl:choose>



                    </xsl:variable>

                <xsl:choose>

                    <xsl:when test="current-group()[matches(.,$fnTerm,'i')]"
>

                        <xsl:variable name="myText">

                            <xsl:value-of select=
"current-group()/preceding::text()[1]"/>

                        </xsl:variable>
                        <xsl:variable name="myTerm">
                            <xsl:value-of select="tokenize($myText,'
')[last()]"/>
                        </xsl:variable>
                        <xsl:analyze-string select="." regex="{$myTerm}">

<xsl:matching-substring></xsl:matching-substring>
                            <xsl:non-matching-substring>
                                <xsl:apply-templates select="."/>
                            </xsl:non-matching-substring>
                        </xsl:analyze-string>
                        <span class="classic" fnTerm="{$fnTerm}"
data-tooltip="{normalize-space($tooltip_text)}" data-tooltip-position=
"bottom">
                            <xsl:value-of select="$myTerm"/>
                        </span>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:apply-templates select="current-group()">
</xsl:apply-templates>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each-group>
        </xsl:copy>
    </xsl:template>

>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/723745> (by
> email <>)

Current Thread