问题
XML and the XSLT 2.0 files for this question are found at https://xsltfiddle.liberty-development.net/6qVRKwX/3
I am trying to 'move' an element ahead of outputting a section of HTML. This element was created during the first part of the transformation) using @mode
to insert footnote numbers into the text. The first mode fn-add-marker
creates <fn-marker/>
to hold the footnote number. The second mode number
then inserts incremented footnote numbers. All of this works fine (through to line 52 and then after 68 in the XSLT fiddle).
Now I need to 'move' an element into the sibling element that spawned it in the mode above. I've combined this with the HTML output: the final idea is that element <tei:seg>
is transformed into HTML <p>
such that this :
<seg type="dep_event">text</seg><fn-marker>incremented no.</fn-marker>
Now becomes this HTML (where seg
= p
, and fn-marker
= sup
:
<p>text<sup>incremented no.</sup></p>
ie. where a condition is met, the footnote is brought inside a sibling element to be contained in <p>
.
The code I inserted (below) works for 3 of 4 needed steps to accomplish this move. It seems the code associated with step 3 does not locate a value in <fn-marker/>
. But if I remove all this, the value is in fact there! It makes me think this is a problem of modes.
The code below does this:
output each instance of
<tei:seg @type="dep_event>"
into a<p>
workscreate the
<sup>
inside the<seg>
that meets the sibling condition workscopy the text() content of
<fn-marker>
into the<sup>
that meets the sibling condition does not workdestroy the old
<fn-marker>1</fn-marker>
works
Referring to line numbers at https://xsltfiddle.liberty-development.net/6qVRKwX/3:
line 56-63:
<xsl:template match="tei:seg[@type='dep_event']">
<p>
<xsl:apply-templates/>
<xsl:if test="following-sibling::node()[1][self::tei:fn-marker]">
<!-- next line of code does not find a value in /text() -->
<sup><xsl:value-of select="./following-sibling::node()[1][self::tei:fn-marker/]text()"/></sup>
</xsl:if>
</p>
</xsl:template>
line 66:
<xsl:template match="tei:fn-marker[preceding-sibling::node()[1][self::tei:seg[@type='dep_event']]]"/>
Thanks in advance.
来源:https://stackoverflow.com/questions/52874845/xslt-2-0-moving-a-node-created-in-first-step-of-a-multi-step-transformation