If clause

Monday, 18 February 2019 · 14 messages · last reply 4 Mar 2019
GC
Giuseppe G. A. Celano18 Feb 2019 15:19 #
Hi, I see that in BaseX 9.1.2 an expression such as "if (3) then 4 " does not raise an error, even if the "else" part is missing. Is this correct? Ciao, Giuseppe
GS
George Sofianos18 Feb 2019 15:23 #
It is for BaseX, take a look at [1]. There is also an elvis operator on the same wiki page. Personally I don't like to deviate from specifications so I try to avoid it. [1] - http://docs.basex.org/wiki/XQuery_Extensions#If_Without_Else
Quoted text · Giuseppe G. A. Celano · 9 lines
On 2/18/19 4:19 PM, Giuseppe G. A. Celano wrote: > Hi, > > I see that in BaseX 9.1.2 an expression such as "if (3) then 4 " does > not raise an error, even if the "else" part is missing. Is this correct? > > Ciao, > Giuseppe >
Best, George
MB
Mark Bordelonin reply to Giuseppe G. A. Celano, 18 Feb 2019, 15:1926 Feb 2019 08:54 #
Guten Tag, Love my basex, have been using it for years. I particularly love being able to have access to all the powerful 2.0 syntax. But I have a question about some behavior I am seeing in the following-sibling axis that does not seem logical to me. Here is the data stored in basex:
Quoted text · Giuseppe G. A. Celano · 1 line
> xquery /text[@id='test']
<text id="test">
  <clause>
    <word>A</word>a
    <word>B</word>
    <word>C</word>c
  </clause>
</text>
Here is the query on that data:
Quoted text · Giuseppe G. A. Celano · 1 line
> xquery /text[@id='test']//word/concat(text(), ' ', normalize-space(./following-sibling::text()[1]))
A a B c C c The same query run in https://www.freeformatter.com/xpath-tester.html <https://www.freeformatter.com/xpath-tester.html> in the same xml gives me the predictable result that I need: String='A a’ String='B ‘ String='C c' Is there any way to alter my query to get the above result in basex? I imagine that this an xpath1.0 vs xpath2.0 issue. Thanks, Mark Bordelon.
MH
Martin Honnen26 Feb 2019 08:55 #
Quoted text · Mark Bordelon · 17 lines
Am 26.02.2019 um 07:54 schrieb Mark Bordelon: > Guten Tag, > Love my basex, have been using it for years. I particularly love being > able to have access to all the powerful 2.0 syntax. > But I have a question about some behavior I am seeing in the > *following-sibling* axis that does not seem logical to me. > > Here is the data stored in basex: > > xquery /text[@id='test'] > <text id="test"> > <clause> > <word>A</word>a > <word>B</word> > <word>C</word>c > </clause> > </text> >
How did you store/parse it, in particular did you use any options to strip white space?
Quoted text · Mark Bordelon · 18 lines
> Here is the query on that data: > > *xquery /text[@id='test']//word/concat(text(), ' ', > normalize-space(./following-sibling::text()[1]))* > A a > B *c* > C c > > The same query run in > https://www.freeformatter.com/xpath-tester.html in the same xml gives > me the predictable result that I need: > String='A a’ > String='B ‘ > String='C c' > > > Is there any way to alter my query to get the above result in basex? I > imagine that this an xpath1.0 vs xpath2.0 issue. >
That path with a function call in the (last) step isn't allowed in XPath 1.0 at all.
MH
Martin Honnenin reply to Mark Bordelon, 26 Feb 2019, 08:5426 Feb 2019 09:48 #
Quoted text · Mark Bordelon · 21 lines
Am 26.02.2019 um 07:54 schrieb Mark Bordelon: > But I have a question about some behavior I am seeing in the > *following-sibling* axis that does not seem logical to me. > > Here is the data stored in basex: > > xquery /text[@id='test'] > <text id="test"> > <clause> > <word>A</word>a > <word>B</word> > <word>C</word>c > </clause> > </text> > > Here is the query on that data: > > *xquery /text[@id='test']//word/concat(text(), ' ', > normalize-space(./following-sibling::text()[1]))* > A a > B *c* > C c >
I think the result you get is caused by whitespace chopping during XML parsing, seems to be the default, see http://docs.basex.org/wiki/Command-Line_Options |-w| Toggles whitespace chopping of XML text nodes. By default, whitespaces will be chopped.
MS
Michael Seiferle26 Feb 2019 14:50 #
Hi Mark, Hi Martin, yes Martin is right, the whitespace will be chopped by default leading to the observed behavior. If you wanted to preserve whitespace globally, you can do that when creating your database. If you only want to preserve whitespace for a given element you may do this as well:
Quoted text · Martin Honnen · 10 lines
> let $db := > '<text id="test"> > <clause xml:space="preserve"> > <word>A</word>a > <word>B</word> > <word>C</word>c > </clause> > </text>' => parse-xml() (: have to actually parse it for the whitespace preserve to have a an effect :) > > return $db//word/concat(text(), ' ', normalize-space(./following-sibling::text()[1]))
Which returns:
Quoted text · Martin Honnen · 3 lines
> A a > B > C c
Best Michael
Quoted text · Martin Honnen · 9 lines
> > Am 26.02.2019 um 09:48 schrieb Martin Honnen <martin.honnen at gmx.de>: > > > I think the result you get is caused by whitespace chopping during XML parsing, seems to be the default, seehttp://docs.basex.org/wiki/Command-Line_Options <http://docs.basex.org/wiki/Command-Line_Options> > -w Toggles whitespace chopping of XML text nodes. By default, whitespaces will be chopped. > > >
MB
Mark Bordelon26 Feb 2019 17:16 #
Thanks Martin and Michael for the “sofortige Antoworten”. Forgive my lack of understanding about the particular of whitespace processing and how BASEX deals with them. To answer Martin’s questions: 1) I stored that xml (as I do all of my email) in the database using this commands in the basex shell: ADD TO PROSE.test test.xml after I created the file in vi on my desktop. I had no xml preamble or any processing instructions about the whitespace. 2) I am also querying in the basex using XQUERY. In short,I need to get the result with the actual text node after the element I target, even if it is null, not the next element’s non-null text. Given my storage, is adjusting the XPATH the way Kristian suggested the best way to achieve my goal? Concretely, how can I adjust how XQUERY executes the path directly to deal with the whitespace issue? I cannot use parse-xml(). Do I add the -w option to the XQUERY that I call from the basex client? And concretely, how can I store the XML with preamble or processing instruction about whitespace to achieve my result?
Quoted text · Michael Seiferle · 40 lines
> On Feb 26, 2019, at 05:50, Michael Seiferle <ms at basex.org> wrote: > > Hi Mark, > Hi Martin, > > yes Martin is right, the whitespace will be chopped by default leading to the observed behavior. > > If you wanted to preserve whitespace globally, you can do that when creating your database. > If you only want to preserve whitespace for a given element you may do this as well: > >> let $db := >> '<text id="test"> >> <clause xml:space="preserve"> >> <word>A</word>a >> <word>B</word> >> <word>C</word>c >> </clause> >> </text>' => parse-xml() (: have to actually parse it for the whitespace preserve to have a an effect :) >> >> return $db//word/concat(text(), ' ', normalize-space(./following-sibling::text()[1])) > > Which returns: >> A a >> B >> C c > > > Best > Michael > >> >> Am 26.02.2019 um 09:48 schrieb Martin Honnen <martin.honnen at gmx.de <mailto:martin.honnen at gmx.de>>: >> >> >> I think the result you get is caused by whitespace chopping during XML parsing, seems to be the default, seehttp://docs.basex.org/wiki/Command-Line_Options <http://docs.basex.org/wiki/Command-Line_Options> >> -w Toggles whitespace chopping of XML text nodes. By default, whitespaces will be chopped. >> >> >> >
MB
Mark Bordelon26 Feb 2019 19:37 #
My follow-up was too hasty, and I forgot to mention that I had tried starting up basex with -w, but it break so many other things that I cannot use this GLOBAL approach. I need to instruct either at the XQUERY command level or at the xml file level. By the way, Kirstian, THANK YOU does work in the simplified data I gave for my original post. Unfortunately your solution does not work in more complicated examples of my datt. If you’re interested in what the real data looks like and the continuing issue, please hit me off-list. Thanks gentlemen! Mark
Quoted text · Mark Bordelon · 58 lines
> On Feb 26, 2019, at 07:16, Mark Bordelon <markcbordelon at yahoo.com> wrote: > > Thanks Martin and Michael for the “sofortige Antoworten”. > Forgive my lack of understanding about the particular of whitespace processing and how BASEX deals with them. > To answer Martin’s questions: > 1) I stored that xml (as I do all of my email) in the database using this commands in the basex shell: > ADD TO PROSE.test test.xml > after I created the file in vi on my desktop. > I had no xml preamble or any processing instructions about the whitespace. > 2) I am also querying in the basex using XQUERY. > > In short,I need to get the result with the actual text node after the element I target, even if it is null, not the next element’s non-null text. > > Given my storage, is adjusting the XPATH the way Kristian suggested the best way to achieve my goal? > Concretely, how can I adjust how XQUERY executes the path directly to deal with the whitespace issue? I cannot use parse-xml(). Do I add the -w option to the XQUERY that I call from the basex client? > And concretely, how can I store the XML with preamble or processing instruction about whitespace to achieve my result? > >> On Feb 26, 2019, at 05:50, Michael Seiferle <ms at basex.org <mailto:ms at basex.org>> wrote: >> >> Hi Mark, >> Hi Martin, >> >> yes Martin is right, the whitespace will be chopped by default leading to the observed behavior. >> >> If you wanted to preserve whitespace globally, you can do that when creating your database. >> If you only want to preserve whitespace for a given element you may do this as well: >> >>> let $db := >>> '<text id="test"> >>> <clause xml:space="preserve"> >>> <word>A</word>a >>> <word>B</word> >>> <word>C</word>c >>> </clause> >>> </text>' => parse-xml() (: have to actually parse it for the whitespace preserve to have a an effect :) >>> >>> return $db//word/concat(text(), ' ', normalize-space(./following-sibling::text()[1])) >> >> Which returns: >>> A a >>> B >>> C c >> >> >> Best >> Michael >> >>> >>> Am 26.02.2019 um 09:48 schrieb Martin Honnen <martin.honnen at gmx.de <mailto:martin.honnen at gmx.de>>: >>> >>> >>> I think the result you get is caused by whitespace chopping during XML parsing, seems to be the default, seehttp://docs.basex.org/wiki/Command-Line_Options <http://docs.basex.org/wiki/Command-Line_Options> >>> -w Toggles whitespace chopping of XML text nodes. By default, whitespaces will be chopped. >>> >>> >>> >> >
MB
Mark Bordelon26 Feb 2019 19:53 #
A follow-up: starting basex -w does NOT seem to solve completely my issue after all. Real data (more complicated than the simplified example) still does not query correctly: text nodes from after later elements are displayed in the place of null text nodes. I’ll try to get a better example, still simplified, that shows this.
Quoted text · Mark Bordelon · 68 lines
> On Feb 26, 2019, at 09:37, Mark Bordelon <markcbordelon at yahoo.com> wrote: > > My follow-up was too hasty, and I forgot to mention that I had tried starting up basex with -w, but it break so many other things that I cannot use this GLOBAL approach. > I need to instruct either at the XQUERY command level or at the xml file level. > By the way, Kirstian, THANK YOU does work in the simplified data I gave for my original post. Unfortunately your solution does not work in more complicated examples of my datt. If you’re interested in what the real data looks like and the continuing issue, please hit me off-list. > > Thanks gentlemen! > Mark > >> On Feb 26, 2019, at 07:16, Mark Bordelon <markcbordelon at yahoo.com <mailto:markcbordelon at yahoo.com>> wrote: >> >> Thanks Martin and Michael for the “sofortige Antoworten”. >> Forgive my lack of understanding about the particular of whitespace processing and how BASEX deals with them. >> To answer Martin’s questions: >> 1) I stored that xml (as I do all of my email) in the database using this commands in the basex shell: >> ADD TO PROSE.test test.xml >> after I created the file in vi on my desktop. >> I had no xml preamble or any processing instructions about the whitespace. >> 2) I am also querying in the basex using XQUERY. >> >> In short,I need to get the result with the actual text node after the element I target, even if it is null, not the next element’s non-null text. >> >> Given my storage, is adjusting the XPATH the way Kristian suggested the best way to achieve my goal? >> Concretely, how can I adjust how XQUERY executes the path directly to deal with the whitespace issue? I cannot use parse-xml(). Do I add the -w option to the XQUERY that I call from the basex client? >> And concretely, how can I store the XML with preamble or processing instruction about whitespace to achieve my result? >> >>> On Feb 26, 2019, at 05:50, Michael Seiferle <ms at basex.org <mailto:ms at basex.org>> wrote: >>> >>> Hi Mark, >>> Hi Martin, >>> >>> yes Martin is right, the whitespace will be chopped by default leading to the observed behavior. >>> >>> If you wanted to preserve whitespace globally, you can do that when creating your database. >>> If you only want to preserve whitespace for a given element you may do this as well: >>> >>>> let $db := >>>> '<text id="test"> >>>> <clause xml:space="preserve"> >>>> <word>A</word>a >>>> <word>B</word> >>>> <word>C</word>c >>>> </clause> >>>> </text>' => parse-xml() (: have to actually parse it for the whitespace preserve to have a an effect :) >>>> >>>> return $db//word/concat(text(), ' ', normalize-space(./following-sibling::text()[1])) >>> >>> Which returns: >>>> A a >>>> B >>>> C c >>> >>> >>> Best >>> Michael >>> >>>> >>>> Am 26.02.2019 um 09:48 schrieb Martin Honnen <martin.honnen at gmx.de <mailto:martin.honnen at gmx.de>>: >>>> >>>> >>>> I think the result you get is caused by whitespace chopping during XML parsing, seems to be the default, seehttp://docs.basex.org/wiki/Command-Line_Options <http://docs.basex.org/wiki/Command-Line_Options> >>>> -w Toggles whitespace chopping of XML text nodes. By default, whitespaces will be chopped. >>>> >>>> >>>> >>> >> >
MH
Martin Honnen26 Feb 2019 20:25 #
Quoted text · Mark Bordelon · 7 lines
Am 26.02.2019 um 18:52 schrieb Mark Bordelon: > A follow-up: starting basex -w does NOT seem to solve completely my > issue after all. Real data (more complicated than the simplified > example) still does not query correctly: text nodes from after later > elements are displayed in the place of null text nodes. > I’ll try to get a better example, still simplified, that shows this. >
Just to make sure, if the data is already in the database and has been inserted with the default whitespace chopping turned on, the result you get for your sample is correct. So at least in my understanding the only way to get the result you want is to make sure the original input XML is inserted again into the database, this time with chopping turned off.
MS
Michael Seiferlein reply to Mark Bordelon, 26 Feb 2019, 19:5327 Feb 2019 10:59 #
Hi Mark, as Martin already stated, the '-w‘-Option has to be active at import time, otherwise the whitespace will be chopped. If I were to do it, I’d reindex all data and explicitly mark all elements that should preserve whitespace, if this is not an option I’d reindex all data with whitespace chopping set to off. Looking forward to your example, I am sure we can figure this out :-) Best Michael
Quoted text · Mark Bordelon · 4 lines
> Am 26.02.2019 um 18:52 schrieb Mark Bordelon <markcbordelon at yahoo.com>: > > A follow-up: starting basex -w does NOT seem to solve completely my issue after all. Real data (more complicated than the simplified example) still does not query correctly: text nodes from after later elements are displayed in the place of null text nodes. > I’ll try to get a better example, still simplified, that shows this.
MB
Mark Bordelon1 Mar 2019 23:53 #
Gentlemen (especially Michael)! My follow-up to my original question from a few days ago: XML:
<sent id="242">
    <clause>
      <word lexmorph="ab|P|">A</word>
      <word lexmorph="to^tus|D|NsCbGn">toto</word>. -<word lexmorph="ab|P|">A</word>
      <word lexmorph="substantia|N|NsCb">substantia</word>
    </clause>.</sent>
XPATH: //clause[word and not(word[not(@lexmorph) or @lexmorph='' or contains(@lexmorph,' ')])]/string-join( word[not(@implicit)]/concat( text() ,'|' ,tokenize(@lexmorph, '\|')[2] ,'|' ,normalize-space(./following-sibling::text()[1]) ),'~~~’) executing this in https://www.freeformatter.com/xpath-tester.html#ad-output <https://www.freeformatter.com/xpath-tester.html#ad-output> returns the (correct) result: A|P|~~~toto|D|. -~~~A|P|~~~substantia|N| executing using XQUERY in basex returns the (incorrect) result: A|P|. -~~~toto|D|. -~~~A|P|~~~substantia|N| executing using XQUERY in basex adding Kristian's [. instance of text()] to the axis returns the (incorrect) result: A|P|. -~~~toto|D|. -~~~A|P|~~~substantia|N| I have tried using the -w option’s true and false values, but my results are always as above. Any ideas?
Quoted text · Michael Seiferle · 21 lines
> On Feb 27, 2019, at 01:59, Michael Seiferle <ms at basex.org> wrote: > > Hi Mark, > > as Martin already stated, the '-w‘-Option has to be active at import time, otherwise the whitespace will be chopped. > > If I were to do it, I’d reindex all data and explicitly mark all elements that should preserve whitespace, if this is not an option I’d reindex all data with whitespace chopping set to off. > > Looking forward to your example, I am sure we can figure this out :-) > > Best > Michael > > > > >> Am 26.02.2019 um 18:52 schrieb Mark Bordelon <markcbordelon at yahoo.com <mailto:markcbordelon at yahoo.com>>: >> >> A follow-up: starting basex -w does NOT seem to solve completely my issue after all. Real data (more complicated than the simplified example) still does not query correctly: text nodes from after later elements are displayed in the place of null text nodes. >> I’ll try to get a better example, still simplified, that shows this. >
LQ
Liam R. E. Quin2 Mar 2019 02:08 #
Quoted text · Mark Bordelon · 5 lines
On Fri, 2019-03-01 at 13:50 -0800, Mark Bordelon wrote: > I have tried using the -w option’s true and false values, but my > results are always as above. > > Any ideas?
Try removing all whitespace between tags that's not part of the actual document and see if you get different results; if so, i'd suspect -w isn't working, perhaps?
-- Liam Quin, https://www.delightfulcomputing.com/ Available for XML/Document/Information Architecture/XSLT/ XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. Web slave for vintage clipart http://www.fromoldbooks.org/
ZD
Zimmel, Danielin reply to Mark Bordelon, 1 Mar 2019, 23:534 Mar 2019 10:09 #
Nothing wrong here with BaseX behavior. If your xml import chops the whitespace, following-sibling::text()[1] will of course always match “.-“ for the first two word nodes. Cheers, Daniel
Quoted text · Mark Bordelon · 34 lines
Von: Mark Bordelon [mailto:markcbordelon at yahoo.com] Gesendet: Freitag, 1. März 2019 22:51 An: Michael Seiferle Cc: BaseX Betreff: Re: [basex-talk] following-sibling axis -- real data example Gentlemen (especially Michael)! My follow-up to my original question from a few days ago: XML: <sent id="242"> <clause> <word lexmorph="ab|P|">A</word> <word lexmorph="to^tus|D|NsCbGn">toto</word>. -<word lexmorph="ab|P|">A</word> <word lexmorph="substantia|N|NsCb">substantia</word> </clause>.</sent> XPATH: //clause[word and not(word[not(@lexmorph) or @lexmorph='' or contains(@lexmorph,' ')])]/string-join( word[not(@implicit)]/concat( text() ,'|' ,tokenize(@lexmorph, '\|')[2] ,'|' ,normalize-space(./following-sibling::text()[1]) ),'~~~’) executing this in https://www.freeformatter.com/xpath-tester.html#ad-output returns the (correct) result: A|P|~~~toto|D|. -~~~A|P|~~~substantia|N| executing using XQUERY in basex returns the (incorrect) result: A|P|. -~~~toto|D|. -~~~A|P|~~~substantia|N| executing using XQUERY in basex adding Kristian's [. instance of text()] to the axis returns the (incorrect) result: A|P|. -~~~toto|D|. -~~~A|P|~~~substantia|N| I have tried using the -w option’s true and false values, but my results are always as above. Any ideas? On Feb 27, 2019, at 01:59, Michael Seiferle <ms at basex.org<mailto:ms at basex.org>> wrote: Hi Mark, as Martin already stated, the '-w‘-Option has to be active at import time, otherwise the whitespace will be chopped. If I were to do it, I’d reindex all data and explicitly mark all elements that should preserve whitespace, if this is not an option I’d reindex all data with whitespace chopping set to off. Looking forward to your example, I am sure we can figure this out :-) Best Michael Am 26.02.2019 um 18:52 schrieb Mark Bordelon <markcbordelon at yahoo.com<mailto:markcbordelon at yahoo.com>>: A follow-up: starting basex -w does NOT seem to solve completely my issue after all. Real data (more complicated than the simplified example) still does not query correctly: text nodes from after later elements are displayed in the place of null text nodes. I’ll try to get a better example, still simplified, that shows this.

⚡Generated with XQuery