Namespaces in element constructors

Friday, 30 December 2016 · 4 messages · last reply 3 Jan 2017
BD
Bridger Dyson-Smith30 Dec 2016 01:29 #
Hi all - I think that I weak grasp of the practical requirements, but I'm unable to find a reference in the spec to clarify what's happening in the following: I have a constructor:
return(
  for $item in $file-list
  let $item-less := replace($item, '^\d{1,}-', '')
  (: returns "missing" supplemental files  :)
  where ($item-less[(not(. = ($files-titles, $excludes)))])
    or ($item-less[(. = $files-titles)])
  return(
    <relatedItem>
      <title>{$item-less}</title>
      <mimeType>
        {if ($item-less = $files-titles)
          then ($content/files/file/name[. =
$item-less]/following-sibling::mimetype/text())
          else
(fetch:content-type(concat(file:parent(document-uri($doc)),$item)))}
      </mimeType>
      <uri>{file:parent(document-uri($doc))}</uri>
    </relatedItem>
  )
)
and it works fine so long at the <relatedItem> is not namespaced. As soon as the <relatedItem> is namespaced; e.g. <relatedItem xmlns=" http://bridger.net">, then I need to use the following XPath in the then keyword:
($content/*:files/*:file/*:name[. =
$item-less]/following-sibling::*:mimetype/text())
The input documents (in the SSCCE, under sample-data/*/metadata.xml) are not in a namespace. Would someone mind providing some context for the "why" here? I've been looking through Priscilla Walmsley's 2nd edition, and the specification, but haven't been able to find an answer. I'm almost certainly looking for the wrong thing(s). Any help will be greatly appreciated! Thank you in advance. Best, Bridger
BD
Bridger Dyson-Smith30 Dec 2016 01:31 #
Why not attach that SSCCE, too? :) Apologies, Bridger
Quoted text · Bridger Dyson-Smith · 48 lines
On Thu, Dec 29, 2016 at 6:29 PM, Bridger Dyson-Smith <bdysonsmith at gmail.com> wrote: > Hi all - > I think that I weak grasp of the practical requirements, but I'm unable to > find a reference in the spec to clarify what's happening in the following: > > I have a constructor: > return( > for $item in $file-list > let $item-less := replace($item, '^\d{1,}-', '') > (: returns "missing" supplemental files :) > where ($item-less[(not(. = ($files-titles, $excludes)))]) > or ($item-less[(. = $files-titles)]) > return( > <relatedItem> > <title>{$item-less}</title> > <mimeType> > {if ($item-less = $files-titles) > then ($content/files/file/name[. = $item-less]/following-sibling: > :mimetype/text()) > else (fetch:content-type(concat(file:parent(document-uri($doc) > ),$item)))} > </mimeType> > <uri>{file:parent(document-uri($doc))}</uri> > </relatedItem> > ) > ) > > and it works fine so long at the <relatedItem> is not namespaced. As soon > as the <relatedItem> is namespaced; e.g. <relatedItem xmlns=" > http://bridger.net">, then I need to use the following XPath in the > `then` keyword: > > ($content/*:files/*:file/*:name[. = $item-less]/following-sibling: > :*:mimetype/text()) > > The input documents (in the SSCCE, under sample-data/*/metadata.xml) are > not in a namespace. > > Would someone mind providing some context for the "why" here? I've been > looking through Priscilla Walmsley's 2nd edition, and the specification, > but haven't been able to find an answer. I'm almost certainly looking for > the wrong thing(s). > > Any help will be greatly appreciated! Thank you in advance. > Best, > Bridger >
CG
Christian Grünin reply to Bridger Dyson-Smith, 30 Dec 2016, 01:292 Jan 2017 11:55 #
Hi Bridger, Sorry for letting you wait:
Quoted text · Bridger Dyson-Smith · 1 line
> and it works fine so long at the <relatedItem> is not namespaced.
I tried to further strip down your code. Do you think that the following examples are equivalent? WORKS:
  let $content := document { <root>BLA</root> }
  return <item>{ $content/root }</item>
DOES NOT WORK:
  let $content := document { <root>BLA</root> }
  return <item xmlns='ns'>{ $content/root }</item>
This is indeed compliant with the spec. The hint may be a bit hidden, but the spec states that “[…] the default element/type namespace may be affected by namespace declaration attributes found inside the element constructor.”. I agree that the decision is somewhat counterintuitive, because you would expect that moving your code to a different place will not change its behavior. Hope this helps, Christian [1] https://www.w3.org/TR/xquery-31/#id-element-constructor
Quoted text · Bridger Dyson-Smith · 12 lines
> > The input documents (in the SSCCE, under sample-data/*/metadata.xml) are not > in a namespace. > > Would someone mind providing some context for the "why" here? I've been > looking through Priscilla Walmsley's 2nd edition, and the specification, but > haven't been able to find an answer. I'm almost certainly looking for the > wrong thing(s). > > Any help will be greatly appreciated! Thank you in advance. > Best, > Bridger
BD
Bridger Dyson-Smith3 Jan 2017 00:34 #
Hi Christian,
Quoted text · Christian Grün · 6 lines
On Mon, Jan 2, 2017 at 5:55 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Bridger, > > Sorry for letting you wait: >
It's no trouble at all -- thank you for your time and trouble.
Quoted text · Christian Grün · 17 lines
> > > and it works fine so long at the <relatedItem> is not namespaced. > > I tried to further strip down your code. Do you think that the > following examples are equivalent? > > WORKS: > > let $content := document { <root>BLA</root> } > return <item>{ $content/root }</item> > > DOES NOT WORK: > > let $content := document { <root>BLA</root> } > return <item xmlns='ns'>{ $content/root }</item> > > HA! That's a *much* better expression of the problem - thank you for
condensing it!
Quoted text · Christian Grün · 13 lines
> This is indeed compliant with the spec. The hint may be a bit hidden, > but the spec states that “[…] the default element/type namespace may > be affected by namespace declaration attributes found inside the > element constructor.”. > > I agree that the decision is somewhat counterintuitive, because you > would expect that moving your code to a different place will not > change its behavior. > > Hope this helps, > Christian > > Absolutely. Again, thank you kindly for your help!
Happy New Year. Best, Bridger
Quoted text · Christian Grün · 19 lines
> [1] https://www.w3.org/TR/xquery-31/#id-element-constructor > > > > > > > The input documents (in the SSCCE, under sample-data/*/metadata.xml) are > not > > in a namespace. > > > > Would someone mind providing some context for the "why" here? I've been > > looking through Priscilla Walmsley's 2nd edition, and the specification, > but > > haven't been able to find an answer. I'm almost certainly looking for the > > wrong thing(s). > > > > Any help will be greatly appreciated! Thank you in advance. > > Best, > > Bridger >

⚡Generated with XQuery