Re: Problem with "preceding" and "following" axis steps
Michael Kay <mike-JkSD5nQpfvpWk0Htik3J/[email protected]> Sun, 15 Nov 2020 20:22:05 +0000
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Message-ID | <[email protected]> |
When i run this with Saxon 10.3 on Java the output is simply
{}
and I think that is correct. You're looking for a text node that comes before a QUOT.START and after a QUOT.END, and there can't be such a node, because the only QUOT.START in the document comes before the only QUOT.END. So neither of the outputs you describe make sense.
I got the same output with Saxon-JS 2.0 on node.js.
So I suspect that you've got something wrong in your question.
From your description of what you're trying to achieve, I would have expected to see something like:
> <xsl:value-of select="text()[preceding-sibling::QUOT.START and following-sibling::QUOT.END]"/>
The preceding-sibling and following-sibling axes seem much more appropriate here then preceding and following, and you surely want the text to have a preceding START and a following END, not the other way around.
But that's not enough to fix it because your stylesheet assumes the presence of //ARTICLE[STI.ART] which doesn't exist in your XML. If I change the code to
<xsl:template match="/">
<xsl:text>{</xsl:text>
<xsl:apply-templates select="//TXT" mode="DEFINITIONS" />
<xsl:text>}</xsl:text>
</xsl:template>
<xsl:template match="ARTICLE" mode="DEFINITIONS">
<xsl:apply-templates select=".//LIST/ITEM/NP/TXT[QUOT.START]" mode="DEFINITIONS"/>
</xsl:template>
<xsl:template match="TXT" mode="DEFINITIONS">
<xsl:text>"</xsl:text>
<xsl:value-of select="text()[preceding-sibling::QUOT.START and following-sibling::QUOT.END]"/>
<xsl:text>": "</xsl:text>
<xsl:apply-templates />
<xsl:text>",</xsl:text>
</xsl:template>
then both Saxon-J and Saxon-JS give me
{"medical device": "medical device means any instrument, apparatus, appliance, software, implant, reagent, material or other article intended by the manufacturer to be used, alone or in combination, for human beings for one or more of the following specific medical purposes:",}Execution time: 47.647855ms
which I assume is the output you are looking for.
It would be interesting to see what the actual code was that gave different results on Saxon-JS and libxslt. It's possible there could be legitimate differences because they're XSLT 1.0 and we're XSLT 3.0, but it seems unlikely.
Michael Kay
Saxonica
> On 15 Nov 2020, at 15:54, Till Gerken <[email protected]> wrote:
>
> Hi,
>
> I have a question regarding the use of "preceding" and "following". I am trying to extract information from Formex documents.
>
> I noticed that there is a difference between Saxon-JS and libxslt and I am not sure if it's my XSLT or if it's a specific Saxon-JS behavior.
>
> Here is a snippet from the source XML that I am processing:
>
> <ITEM>
>
>
> <NP>
>
> <NO.P>(1)</NO.P>
>
> <TXT><QUOT.START CODE="2018" ID="QS0006" REF.END="QE0006"/>medical device<QUOT.END CODE="2019" ID="QE0006" REF.START="QS0006"/> means any instrument, apparatus, appliance, software, implant, reagent, material or other article intended by the manufacturer to be used, alone or in combination, for human beings for one or more of the following specific medical purposes:</TXT>
>
>
> <P>
>
>
> <LIST TYPE="DASH">
>
>
> <ITEM>
>
>
> <P>diagnosis, prevention, monitoring, prediction, prognosis, treatment or alleviation of disease,</P>
>
>
> </ITEM>
>
>
> <ITEM>
>
>
> <P>diagnosis, monitoring, treatment, alleviation of, or compensation for, an injury or disability,</P>
>
>
> </ITEM>
>
>
> <ITEM>
>
>
> <P>investigation, replacement or modification of the anatomy or of a physiological or pathological process or state,</P>
>
>
> </ITEM>
>
>
> <ITEM>
>
>
> <P>providing information by means of <HT TYPE="ITALIC">in vitro</HT> examination of specimens derived from the human body, including organ, blood and tissue donations,</P>
>
>
> </ITEM>
>
>
> </LIST>
>
>
> </P>
>
>
> <P>and which does not achieve its principal intended action by pharmacological, immunological or metabolic means, in or on the human body, but which may be assisted in its function by such means.</P>
>
>
> <P>The following products shall also be deemed to be medical devices:</P>
>
>
> <P>
>
>
> <LIST TYPE="DASH">
>
>
> <ITEM>
>
>
> <P>devices for the control or support of conception;</P>
>
>
> </ITEM>
>
>
> <ITEM>
>
>
> <P>products specifically intended for the cleaning, disinfection or sterilisation of devices as referred to in Article 1(4) and of those referred to in the first paragraph of this point.</P>
>
>
> </ITEM>
>
>
> </LIST>
>
>
> </P>
>
>
> </NP>
> </ITEM>
>
> Here are the XSLT instructions I am using:
>
> <xsl:template match="/">
> <xsl:text>{</xsl:text>
> <xsl:apply-templates select="//ARTICLE[STI.ART[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜÉÈÊÀÁÂÒÓÔÙÚÛÇÅÏÕÑŒ', 'abcdefghijklmnopqrstuvwxyzäöüéèêàáâòóôùúûçåïõñœ'),'definitions')]]" mode="DEFINITIONS" />
> <xsl:text>}</xsl:text>
> </xsl:template>
>
> <xsl:template match="ARTICLE" mode="DEFINITIONS">
> <xsl:apply-templates select=".//LIST/ITEM/NP/TXT[QUOT.START]" mode="DEFINITIONS"/>
> </xsl:template>
> <xsl:template match="TXT" mode="DEFINITIONS">
> <xsl:text>"</xsl:text>
> <xsl:value-of select="text()[following::QUOT.START and preceding::QUOT.END]"/>
> <xsl:text>": "</xsl:text>
> <xsl:apply-templates />
> <xsl:text>",</xsl:text>
> </xsl:template>
>
> My issue is with the statement "<xsl:value-of select="text()[following::QUOT.START and preceding::QUOT.END]"/>"
>
> libxslt only returns the word between QUOT.START and QUOT.END, in the example above that would be "medical device". (my desired result)
>
> Saxon-JS however returns the text of the entire TXT tag. (not my desired result)
>
> Is there an error in my XSLT or did I come across an implementation-specific behavior of Saxon-JS? In case of the latter, what would be the right way to extract only the piece between QUOT.START and QUOT.END?
>
> Thanks!
>
> Till
>
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help