<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>29374</bug_id>
          
          <creation_ts>2016-01-14 00:22:56 +0000</creation_ts>
          <short_desc>fn:transform</short_desc>
          <delta_ts>2016-03-22 09:40:10 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>Functions and Operators 3.1</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>WORKSFORME</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Benito van der Zander">benito</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          <cc>abel.braaksma</cc>
    
    <cc>andrew_coleman</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>124583</commentid>
    <comment_count>0</comment_count>
    <who name="Benito van der Zander">benito</who>
    <bug_when>2016-01-14 00:22:56 +0000</bug_when>
    <thetext>It is strange that in XQuery the function to load an xquery module has the long name fn:load-xquery-module, but the function to run an xsl transformation has the short name fn:transform. After all, when you write XQuery, XQuery is already implicitly used, so you rather expect a short fn:load-module or even just fn:module. While XSLT is an entire different language, so it seems more logical to have fn:run-xslt or fn:xsl-transform. Seems it was heavily influenced by a XSLT working group, but it is an XPath function, not an XSLT function...

I hope a standalone XQuery processor is not required to support fn:transform.


And unfortunately I already have a custom transform function in my implementation.
Defined as 

pxp:transform($root as item()*, $f as function(*), $options as map()) as item()*){
 for $i in $root return $f($i)!(if (. instance of node() and ( . is $i or $options(&quot;always-recurse&quot;) ) ) then (
                 typeswitch (.)
                   case element() return element {node-name(.)} { @* ! $f(.), node()!pxp:transform(., $f, $options) }
                   case document-node() return document {  node() ! pxp:transform(., $f, $options) }
                   default return .
              ) else . )
}              
pxp:transform($root as item()*, $f as function(*)) as item()* { pxp:transform($root, $f, {}) }
pxp:transform($f as function(*)) as item()* { pxp:transform(., $f, {}) }


That is quite useful to perform a map/filter over all nodes in a document. 
E.g. For example transform(/, function($x) { if (name($x) = &quot;a&quot;) then &lt;a&gt;{$x/@*, &lt;b&gt;{$x/node()}&lt;/b&gt;}&lt;/a&gt; else $x } ) to make all a-links bold; or  transform(/, function($x) { if (name($x) = &quot;a&quot;) then () else $x } ) to remove them.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124589</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-01-14 10:15:15 +0000</bug_when>
    <thetext>Can&apos;t really comment on the name; these things happen. Some of us like short names, some like long names, but we all hate meetings where a lot of time is spent on deciding the best terminology. The function names evolved as their specification evolved: the original idea was to have something that dynamically executed a query, but we decided that dynamically loading a query and making its functions available for execution was much more powerful, so the name changed to reflect this.

I believe the current state of the conformance rules is that a query processor is required to recognize the fn:transform function, but it is allowed to throw a dynamic error if &quot;no suitable XSLT processor is available&quot;. This means queries can be made interoperable provided they are written using try-catch.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124590</commentid>
    <comment_count>2</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-01-14 12:08:03 +0000</bug_when>
    <thetext>Naming is always tricky, but there&apos;s a big difference here. The fn:load-query-module loads a module and exposes its functions, but does *not* execute it. The fn:transform actually invokes a transformation, but does *not* make its functions available (this does, however, beg the question: why can&apos;t we load an xslt module or package?).

Your argument suggests that because you are &quot;already in XQuery, it should be a short name&quot;. But these are XPath Functions and Operators shared between multiple languages, fn:load-query-module is therefore also available from XSLT and any other language or environment that exposes F&amp;O.

Since the words load or load-module could mean multiple things, I think the WG made a good decision here. Likewise, transform is a verb used primarily with XSLT, so the added prefix &quot;xsl&quot; seems redundant.

The function was added by the joined WG&apos;s, only recently they asked the XSL WG to update the spec such that it reflected the new state the XSLT spec is in. It seems only reasonable that if in F&amp;O you add a function for XQuery, you also add something for XSLT, as both are the prime languages where F&amp;O is used in.

Whether or not an XQuery processor supports the fn:transform function or an XSLT processor supports the fn:load-query-module function is highly dependent on the implementations and yes, this may mean that such an implementation allows you to configure an external, extra xquery/xslt processor for this task.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124655</commentid>
    <comment_count>3</comment_count>
    <who name="Andrew Coleman">andrew_coleman</who>
    <bug_when>2016-01-21 11:29:54 +0000</bug_when>
    <thetext>The WGs discussed this at the Joint WG teleconference on 2015-01-19 and agreed to keep these function names unchanged.

Many thanks for the discussion.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>