Project

Profile

Help

Feature #3572

closed

Have an extra attribute for ixsl:set-attribute to select the element to be affected

Added by Pieter Masereeuw about 7 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Low
Category:
IXSL extensions
Sprint/Milestone:
-
Start date:
2017-12-12
Due date:
% Done:

100%

Estimated time:
Applies to JS Branch:
1.0, Trunk
Fix Committed on JS Branch:
Trunk
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

It would be nice if <ixsl:set-attribute> had an extra attribute so that it would not work on the current element, but on the element referenced by that attribute, much in the same way as the object attribute of <ixsl:set-property>. As it works now, setting an attribute often needs much code, such as a construct with <xsl:for-each>.

Actions #1

Updated by Debbie Lockett almost 7 years ago

Consider this for Saxon-JS 2.0, and Saxon 9.9.

Actions #2

Updated by Debbie Lockett almost 7 years ago

  • Subject changed from Have an extra attribute for >ixsl:set-attribute> to select the element to be affected to Have an extra attribute for ixsl:set-attribute to select the element to be affected
Actions #3

Updated by Debbie Lockett over 6 years ago

  • Description updated (diff)
Actions #4

Updated by Debbie Lockett over 5 years ago

Relatedly: referring to the Saxon-CE documentation, the design for ixsl:set-attribute was inspired by xsl:attribute: "The instruction has attributes name, namespace, and select, and works in exactly the same way as xsl:attribute, except that the attribute is written directly to the current element." For some reason, we lost the namespace attribute in Saxon-JS, but it would be useful if this was reinstated.

Actions #5

Updated by Debbie Lockett over 5 years ago

  • Status changed from New to In Progress
  • Assignee set to Debbie Lockett
  • Applies to JS Branch 1.0, Trunk added
  • Fix Committed on JS Branch Trunk added

Committed changes on Saxon-JS 2.0 branch, and 10.0 trunk.

Added @object optional attribute for ixsl:set-attribute and ixsl:remove-attribute. When no object attribute is present, the current node is used. This brings these extension instructions closer in line with ixsl:set-property and ixsl:set-style, rather than xsl:attribute.

JS2unit tests added (ixsl2/setAttr05, setAttr15).

Further to the additional point about ixsl:set-attribute/@namespace: in fact it is not worthwhile reinstating, and actually the namespace attribute on ixsl:remove-attribute can be removed. In either case, the @namespace attribute is unnecessary, since to set/remove attributes in a namespace, an EQName can be supplied for @name. (There is actually a bug here in Saxon-JS 1.x; but this has been fixed on the 2.0 branch.)

In Saxon 9.9 and earlier, ixsl:remove-attribute/@namespace is accepted at compile time, but was not implemented properly in Saxon-JS 1.x, as the value was ignored at runtime. For 10.0, the @namespace attribute has been removed entirely. Since it wasn't working anyway, the reference to this attribute in the Saxon-JS documentation has recently been removed (see Bug #4241).

Actions #6

Updated by Debbie Lockett over 5 years ago

Further fix committed on 2.0 branch for when ixsl:set-attribute/@name is supplied as a URIQualifiedName (i.e. in the form Q{uri}local). Now check in scope namespaces of the HTML element the attribute is to be added to, to find a suitable prefix to be used for the attribute name.

For example, if the XSLT stylesheet contains the namespace declaration xmlns:svg="http://www.w3.org/2000/svg", and the Xlink namespace is in scope for the relevant svg:image element in the HTML page, and bound to the xlink prefix, the following instruction:

<ixsl:set-attribute name="Q{{http://www.w3.org/1999/xlink}}href" 
            select="'../../src/logo.gif'"
            object="(ixsl:page()//svg:svg)[1]/svg:image"/>

will set the xlink:href attribute (i.e. localName "href", namespaceURI "http://www.w3.org/1999/xlink", prefix "xlink") on the svg:image element.

Without this prefix fixup, the attribute set has localName "href", namespaceURI "http://www.w3.org/1999/xlink", and prefix null. Which looks wrong in the page, and can produce unexpected results (e.g. svg:image/@href returns a value as well as svg:image/@xlink:href).

Actions #7

Updated by Pieter Masereeuw over 5 years ago

I can't wait to use this feature - it will save a lot of code (and make the code more clear). But I wonder what happens if the object attribute references more than just one element? I can imagine that all elements will be affected, but also that you want to restrict the use of the attribute to one element only. After all, it is called object and not objects.

BTW the same applies for ixsl:set-property and ixsl:set-style. Of course, behaviour of all instructions should be identical.

Actions #8

Updated by Debbie Lockett over 5 years ago

Yes, currently there is a cardinality check that the value supplied for the object attribute (i.e. the result of evaluating the expression) on ixsl:set-attribute and ixsl:remove-attribute is exactly one (as for the object attribute on ixsl:set-property and ixsl:set-style), because it makes sense to be consistent. So there will be an error at run time if object does not reference exactly one HTML element.

I think that if you want to be affecting multiple elements, it makes sense to stick to using xsl:for-each (as currently often used in Saxon-JS 1.x). Do you agree?

Actions #9

Updated by Pieter Masereeuw over 5 years ago

Yes, I agree. Consistency first. And furthermore, using a for-each will make it obvious to the reader of the code that more elements will be affected.

As an aside: because xsl:for-each makes you think of iteration, I always place a comment ("this iterates only once") in my code if I need to use xsl:for-each to merely change the context.

Actions #10

Updated by Debbie Lockett over 5 years ago

  • Status changed from In Progress to Resolved

Updated Saxon-JS 2.0 documentation on dev trunk branch, as appropriate (i.e. add new object attribute for ixsl:remove-attribute and ixsl:set-attribute, update descriptions, details, and examples).

So now marking as resolved for 2.0 trunk.

Actions #11

Updated by Debbie Lockett over 4 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in JS Release set to Saxon-JS 2.0
Actions #12

Updated by Debbie Lockett over 4 years ago

  • Category set to IXSL extensions

Please register to edit this issue

Also available in: Atom PDF Tracking page