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

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>28744</bug_id>
          
          <creation_ts>2009-08-26 10:24:25 -0700</creation_ts>
          <short_desc>XSLTProcessor transformToFragment mistakenly treats source node as root one</short_desc>
          <delta_ts>2023-06-02 04:56:28 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>XML</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=14101</see_also>
          <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="Martin Honnen">martin.honnen</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>ap</cc>
    
    <cc>bfulgham</cc>
    
    <cc>rniwa</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>142881</commentid>
    <comment_count>0</comment_count>
      <attachid>38618</attachid>
    <who name="Martin Honnen">martin.honnen</who>
    <bug_when>2009-08-26 10:24:25 -0700</bug_when>
    <thetext>Created attachment 38618
HTML document with a JavaScript test case using XSLTProcessor transformToFragment

WebKit allows XSLT transformations to be run by Javascript code, exposing the same API that Mozilla introduced: https://developer.mozilla.org/index.php?title=en/The_XSLT%2F%2FJavaScript_Interface_in_Gecko/Interface_List
There is however a major incompatibility between WebKit and between Mozilla. The first argument to the transformToFragment method takes a DOM node and Mozilla (and Opera) then apply the XSLT transformation with that node as the initial context node while WebKit seems to always apply the XSLT transformation to the ownerDocument node of the DOM node passed to transformToFragment.
So with Mozilla the API can be used to apply an XSLT transformation to a certain DOM node (e.g. an element in a larger document) while WebKit always applies the transformation to the complete document.

That is an incompatibility. As the API was introduced by Mozilla and then adapted by WebKit I think WebKit should aim to behave like Mozilla.

The test case I am going to attach runs a simple XSLT transformation with transformToFragment. The stylesheet has two templates, one matching the document node (match=&quot;/&quot;) and a second matching a &apos;foo&apos; element (match=&quot;foo&quot;). Then transformToFragment is called with a &apos;foo&apos; element node in a larger XML document being passed in as the first argument. Mozilla and Opera that way start the transformation by applying the match=&quot;foo&quot; template while WebKit starts the transformation by applying the match=&quot;/&quot; template leading to a transformation result that differs strongly between Mozilla and WebKit.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>143454</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2009-08-28 14:10:48 -0700</bug_when>
    <thetext>This is indeed a serious bug, but the mechanism is somewhat different than described above. The implementation of transformToFragment takes a subtree with a root at source node, and creates a new document from it. So, the &quot;&lt;xsl:template match=&quot;/&quot;&gt;&quot; rule matches &quot;&lt;foo&gt;&quot; node.

Like bug 14101, this will be quite difficult to fix, because our DOM tree cannot be directly processed by XSL, so we cannot just pass a node from DOM.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1887408</commentid>
    <comment_count>2</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2022-07-28 12:22:55 -0700</bug_when>
    <thetext>I am still able to reproduce this bug in Safari 15.6 on macOS 12.5 using attached test case and it shows &quot;Test failed.&quot; and it is same with Chrome Canary 106. Only Firefox Nightly 105 shows &quot;Test succeeded.&quot;. Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1959527</commentid>
    <comment_count>3</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2023-06-02 04:56:28 -0700</bug_when>
    <thetext>*** Chrome Canary 116 &amp; Safari 16.5 / STP171 ***

&lt;div xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;p&gt;bar&lt;/p&gt;&lt;/div&gt;


*** Firefox Nightly 115 ***

&lt;p xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;bar&lt;/p&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>38618</attachid>
            <date>2009-08-26 10:24:25 -0700</date>
            <delta_ts>2009-08-26 10:24:25 -0700</delta_ts>
            <desc>HTML document with a JavaScript test case using XSLTProcessor transformToFragment</desc>
            <filename>test2009082601.html</filename>
            <type>text/html</type>
            <size>1610</size>
            <attacher name="Martin Honnen">martin.honnen</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMDEvL0VOIg0KICAgICAg
ICAiaHR0cDovL3d3dy53My5vcmcvVFIvaHRtbDQvc3RyaWN0LmR0ZCI+DQo8aHRtbCBsYW5nPSJl
biI+DQo8aGVhZD4NCjxtZXRhIGh0dHAtZXF1aXY9IkNvbnRlbnQtVHlwZSIgY29udGVudD0idGV4
dC9odG1sOyBjaGFyc2V0PVVURi04Ij4NCjx0aXRsZT50cmFuc2Zvcm1Ub0ZyYWdtZW50IHRlc3Q8
L3RpdGxlPg0KPHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPg0KZnVuY3Rpb24gZG9UZXN0
KCkNCnsNCiAgdmFyIGRvYyA9IG5ldyBET01QYXJzZXIoKS5wYXJzZUZyb21TdHJpbmcoWw0KICAn
PHJvb3Q+JywNCiAgJzxmb28+YmFyPFwvZm9vPicsDQogICc8XC9yb290PicNCiAgXS5qb2luKCcn
KSwgJ2FwcGxpY2F0aW9uL3htbCcpOw0KICB2YXIgc3R5bGVzaGVldCA9IG5ldy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