Re: [basex-talk] losses von tags?
Am 01.11.2017 um 22:54 schrieb michael4...@arcor.de: Hello, There is a *problem in transforming data vom XML in HTML*. In XML there are HTML-tags included. XML original: *text is important.* HTML goal: *text is important.* (1) result: text is important. let $data := text is important. return {$data/*data()*} (2) result: text is important. let $data := text is important. return {$data/*text()*} (3) result: text is important. let $data := text is important. return {*$data*} Is there another possibility to get the result desired? Use $data/node() to select all child nodes of the "dat" element.
[basex-talk] losses von tags?
Hello, There is a problem in transforming data vom XML in HTML. In XML there are HTML-tags included. XML original: text is important. HTML goal: text is important. (1) result: text is important. let $data := text is important. return {$data/data()} (2) result: text is important. let $data := text is important. return {$data/text()} (3) result: text is important. let $data := text is important. return {$data} Is there another possibility to get the result desired? Thanking you, Michael
Re: [basex-talk] Rounding/parsing decimal vs float
Awesome Leo, thanks! Similar to what I was thinking about but with a lot or after-thought optimization! Great suggestion. M. Il 01 nov 2017 1:59 PM, "Leonard Wörteler" < leonard.woerte...@uni-konstanz.de> ha scritto: > Hi Marco, > > I also do not know of a built-in way to do this, but here is my shot at an > implementation in XQuery. It uses fast exponentiation [1] and throws a > custom error if there is more than one "e" in the input. > > Hope that helps (or is of interest), I had fun hacking it together, > Leo > > declare function local:pow($n, $k) { > if($k eq 0) then xs:decimal('1') > else if($k eq 1) then $n > else ( > let $d := $k idiv 2, > $m := $k mod 2 > return if($m eq 0) then local:pow($n * $n, $d) > else local:pow($n * $n, $d) * $n > ) > }; > > declare function local:parse-decimal($str as xs:string) as xs:decimal { > let $parts := tokenize($str, '[eE]') > return switch(count($parts)) > case 1 return xs:decimal($str) > case 2 return ( > let $exp := xs:long($parts[2]), > $base := xs:decimal($parts[1]), > $b10 := if($exp gt 0) then xs:decimal('10') else > xs:decimal('0.1') > return $base * local:pow($b10, $exp) > ) > default return error(xs:QName('local:NODECIML'), 'Wrong format: ' > || $str) > }; > > local:parse-decimal('123.45e-300') > > [1] https://en.wikipedia.org/wiki/Exponentiation_by_squaring > > Am Mittwoch, 01. November 2017 13:21 CET, Marco Lettere < > m.lett...@gmail.com> schrieb: > > Thanks Kristian, > > unfortunately this introduces rounding errors which I'm trying to avoid > > because managing units, measures and monetary amounts. > > M. > > > > Il 01 nov 2017 12:57 PM, "Kristian Kankainen" ha > > scritto: > > > > You need to use xs:float or xs:double instead of xs:decimal to be able to > > use the 'e' or 'E' as the exponent separator. > > > > Br, > > Kristian K1. nov 2017 13:18 kirjutas kuupäeval Marco Lettere < > > m.lett...@gmail.com>: > > > > > > Hi all, > > > > > > I thought of asking this in parallel of hacking my own parsing > procedure > > > ... > > > > > > Is there a native way to parse scientific notation string into > > > xs:decimal since a direct casting (xs:decimal("1e1")) is not allowed? > > > > > > Thanks, > > > > > > Marco. > > > > >
Re: [basex-talk] ?==?utf-8?q? Rounding/parsing decimal vs float
Hi Marco, I also do not know of a built-in way to do this, but here is my shot at an implementation in XQuery. It uses fast exponentiation [1] and throws a custom error if there is more than one "e" in the input. Hope that helps (or is of interest), I had fun hacking it together, Leo declare function local:pow($n, $k) { if($k eq 0) then xs:decimal('1') else if($k eq 1) then $n else ( let $d := $k idiv 2, $m := $k mod 2 return if($m eq 0) then local:pow($n * $n, $d) else local:pow($n * $n, $d) * $n ) }; declare function local:parse-decimal($str as xs:string) as xs:decimal { let $parts := tokenize($str, '[eE]') return switch(count($parts)) case 1 return xs:decimal($str) case 2 return ( let $exp := xs:long($parts[2]), $base := xs:decimal($parts[1]), $b10 := if($exp gt 0) then xs:decimal('10') else xs:decimal('0.1') return $base * local:pow($b10, $exp) ) default return error(xs:QName('local:NODECIML'), 'Wrong format: ' || $str) }; local:parse-decimal('123.45e-300') [1] https://en.wikipedia.org/wiki/Exponentiation_by_squaring Am Mittwoch, 01. November 2017 13:21 CET, Marco Lettere schrieb: > Thanks Kristian, > unfortunately this introduces rounding errors which I'm trying to avoid > because managing units, measures and monetary amounts. > M. > > Il 01 nov 2017 12:57 PM, "Kristian Kankainen" ha > scritto: > > You need to use xs:float or xs:double instead of xs:decimal to be able to > use the 'e' or 'E' as the exponent separator. > > Br, > Kristian K1. nov 2017 13:18 kirjutas kuupäeval Marco Lettere < > m.lett...@gmail.com>: > > > > Hi all, > > > > I thought of asking this in parallel of hacking my own parsing procedure > > ... > > > > Is there a native way to parse scientific notation string into > > xs:decimal since a direct casting (xs:decimal("1e1")) is not allowed? > > > > Thanks, > > > > Marco. > >
Re: [basex-talk] Rounding/parsing decimal vs float
Thanks Kristian, unfortunately this introduces rounding errors which I'm trying to avoid because managing units, measures and monetary amounts. M. Il 01 nov 2017 12:57 PM, "Kristian Kankainen" ha scritto: You need to use xs:float or xs:double instead of xs:decimal to be able to use the 'e' or 'E' as the exponent separator. Br, Kristian K1. nov 2017 13:18 kirjutas kuupäeval Marco Lettere < m.lett...@gmail.com>: > > Hi all, > > I thought of asking this in parallel of hacking my own parsing procedure > ... > > Is there a native way to parse scientific notation string into > xs:decimal since a direct casting (xs:decimal("1e1")) is not allowed? > > Thanks, > > Marco. >
Re: [basex-talk] Rounding/parsing decimal vs float
You need to use xs:float or xs:double instead of xs:decimal to be able to use the 'e' or 'E' as the exponent separator. Br, Kristian K1. nov 2017 13:18 kirjutas kuupäeval Marco Lettere : > > Hi all, > > I thought of asking this in parallel of hacking my own parsing procedure > ... > > Is there a native way to parse scientific notation string into > xs:decimal since a direct casting (xs:decimal("1e1")) is not allowed? > > Thanks, > > Marco. >
[basex-talk] Rounding/parsing decimal vs float
Hi all, I thought of asking this in parallel of hacking my own parsing procedure ... Is there a native way to parse scientific notation string into xs:decimal since a direct casting (xs:decimal("1e1")) is not allowed? Thanks, Marco.
Re: [basex-talk] Flexible update via function
Hi Michael, > Manipulation of an XML structure with flexible declare function > > If there are some similar issues or solutions in BaseX community, > this will be very interesting. Any other sources to learn more about? You can have a look at the lecture slides that are listed at [1], in particular “XQuery: More than Just a Query Language”. Our documentation contains various practical XQuery examples as well (see e.g. [2]). The 2nd edition of Priscilla Walmsley’s book is one of the best available printed resources [3]. It was published end of 2015, so it includes all new features of XQuery 3 and XQuery 3.1. It takes a while and efforts to explore the full complexity and variety of the XQuery language, but may save you a lot of time in the long term. Christian [1] http://phobos103.inf.uni-konstanz.de/xml15 [2] http://docs.basex.org/wiki/Update [3] http://shop.oreilly.com/product/0636920035589.do > Christian Grün hat am 29. Oktober 2017 um 17:10 geschrieben: > > > Hi Michael, > > Please note that an expression will always be evaluated before its > result will be bound to a variable. > > You didn’t mention what result you would expect. I guess it should be > as follows: > > textBBB > > You could pass on a path string to your function and navigate through > the single steps, e.g. with fold-left [1]: > > declare function local:node-add($xml, $path, $value) { > copy $copy := $xml > modify ( > let $target := fold-left( > tokenize($path, '/'), > $copy, > function($node, $step) { > $node/*[name() = $step] > } > ) > return insert node $value into $target > ) > return $copy > }; > > local:node-add( > text, > 'xml', > BBB > ) > > If you need more flexibility, you can pass on a function that takes > care of the navigation inside the copy/modify or update expression: > > declare function local:node-add($xml, $target, $value) { > $xml update { > insert node $value into $target(.) > } > }; > local:node-add( > document { }, > function($n) { $n/A/B }, > > ) > > Best, > Christian > > [1] http://docs.basex.org/wiki/Higher-Order_Functions#fn:fold-left > > > > On Sun, Oct 29, 2017 at 4:34 PM, wrote: > > Hello, > > How to add/replace a complete node in a node tree, > with done by a function and by according function parameters. > That means with flexible instructions. > > Such as: > > declare function local:NodeAdd($XML, $XMLPath, $XMLValue) > { > ?? > }; > > let $XML := text > let $XMLAdd := BBB > let $XMLPath := $XML/xml > > > return > local:NodeAdd($XML, $XMLPath , $XMLAdd) > > Problem: > Following examples didn't work, because an internal reference to > copy-XML-structure is needed/forced. > > example 1: copy / modify > > declare function local:NodeAdd($XML, $XMLPath, $XMLValue) > { > > copy $XML2 := $XML > modify ( > insert node $XMLValue into $XML2/xml > ) > return > $XML2 > }; > > But: Instead of into $XML2/xml, > > into $XML/xml is needed, respectively into $XMLPath > > > Thanks a lot > Michael
Re: [basex-talk] UnaryLookup expression failure
Hi Günther, Thanks for the concise bug report. I stumbled across a similar issue just recently [1], so I’m glad to confirm that the latest BaseX 9.0 snapshot returns the correct result [2]. All the best, Christian [1] https://github.com/BaseXdb/basex/commit/ab52f2dde2628bbeac5da22898bf6e28f6826751 [2] http://files.basex.org/releases/latest/ On Mon, Oct 30, 2017 at 8:25 PM, Gunther Rademacher wrote: > While testing some XQuery lookup expressions on BaseX 8.6.7, I got a wrong > result for this one: > > (map{'a':(1,3)},map{'a':(2,4)})!?a[2] > > It should have returned the second item of the 'a' entry for each of the maps, > i.e. > > 3 4 > > but it returns just > > 3 > > Apparently the predicate is applied as if everything before it was in > parentheses, i.e. as if it were > > ((map{'a':(1,3)},map{'a':(2,4)})!?a)[2] > > The (simplified) parse tree for the original expression and the XQuery 3.1 > grammar however indicates that the predicate is part of the mapping target > expression: > > > > ... > > ! > > >? >a > > >[ >2 >] > > > > > Best regards > Gunther