[xquery-talk] Help understanding typeswitch-based Identity Transform

Bridger Dyson-Smith bdysonsmith at gmail.com
Thu Feb 15 09:04:11 PST 2018

Hi list --

I'm trying to get a better understanding of identity transforms in Xquery
and I don't understand the finer points of the approaches for dealing with
specific elements.

I've finally to become used to the XSLT approach, using a matching template
to process `field[@name='first']`, e.g. would someone be willing to shine
some light on different methods for dealing with this?

Thanks very much for your time and trouble.


declare variable $input :=
      <title>ABC: The Alphabet</title>
      <author>Some Person</author>
        <field name="first">First Field</field>
        <field name="second">Second Field</field>

declare function local:passthru( $node as node()* ){

declare function local:dispatch(
  $nodes as node()*
) as item()* {
  for $node in $nodes
      case text() return $node
      case element(docs) return local:passthru($node)
      case element(doc) return local:docf($node)
      case element(title) return local:title($node)
      case element(author) return local:author($node)
      case element(fields) return local:passthru($node)
      case element(field) return () (:return empty sequence:)
      default return local:passthru($node)

declare function local:docf($node) {

declare function local:title($node) {

declare function local:author($node) {


Output should look something like:

  <new-title>ABC: The Alphabet</new-title>
  <new-author>Some Person</new-author>
  <new-subject>First Field</new-subject>
    <new-entry>Second Field</new-entry>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20180215/c8f26b20/attachment.html>

More information about the talk mailing list