Page 1 of 1

Insert Attribute with value automatically

Posted: Wed Dec 14, 2022 2:05 pm
by Isabelle
Hello,

We use the oxygen sdk in version 25.0.0.0.
We want to automate the insertion of an attribute with a default value each time an element is inserted.
To do that, we use the cc_common.xml
Here what we have tried :

Code: Select all

  <elementProposals path="eoTopic">
    <insertAttribute name="eoTopicType" value="eott04"/>
  </elementProposals>
Here is the xsd

Code: Select all

<xs:element name="eoTopic" type="eoTopicElemType"/>
<xs:complexType name="eoTopicElemType">
	<xs:element ref="eoTopicContent"/>
	<xs:attribute ref="eoTopicType" use="required"/>
	<xs:attribute ref="id"/>
</xs:complexType>
<xs:attribute name="eoTopicType" type="eoTopicTypeAttType"/>
<xs:simpleType name="eoTopicTypeAttType">
	<xs:restriction base="xs:string">
		<xs:enumeration value="eott01"/>
		<xs:enumeration value="eott02"/>
		<xs:enumeration value="eott03"/>
		<xs:enumeration value="eott04"/>
		<xs:enumeration value="eott05"/>
		<xs:enumeration value="eott06"/>
		<xs:enumeration value="eott07"/>
		<xs:enumeration value="eott08"/>
		<xs:enumeration value="eott09"/>
		<xs:enumeration value="eott10"/>
	</xs:restriction>
</xs:simpleType>
The attribute eoTopicType is well added but the value is empty.
Did we miss something with elementProposals definition ?

Thanks,
Regards,
Isabelle

Re: Insert Attribute with value automatically

Posted: Fri Dec 16, 2022 9:58 am
by alex_jitianu
Hello,
We want to automate the insertion of an attribute with a default value each time an element is inserted.
How do you insert the element? Through the content completion window?
I've created a sample project starting from your code snippets, but I didn't reproduce the issue.
cc_config.zip
Please load the *.xpr file inside the Project view and open sample.xml. Insert an "eoTopic" element inside the root element by using the content completion window. I the attribute value inserted? If it is, do you notice something different between my cc_config.xml/XSD and yours?
You might also try the same scenario inside an Oxygen XML Editor/Author (I can provide a trial license if needed) to understand if the SDK performs differently, somehow.

Best regards,
Alex

Re: Insert Attribute with value automatically

Posted: Fri Dec 16, 2022 11:53 am
by Isabelle
Hi Alex,

Thank you for your feedback.
The issue came from the way we loaded our cc_config.xml file and not from Oxygen.
Sorry for the inconvenience.

Regards,
Isabelle

Re: Insert Attribute with value automatically

Posted: Fri Dec 16, 2022 9:14 pm
by Isabelle
Hi,

I have fixed issue on our side.
Now I have questions about this functionality.

Does it activate when you change an attribute ?

I have this condition :

Code: Select all

  <elementProposals insertElements="quantityGroup" path="quantity[@quantityType='qty04']"/>
But when I change the value of quantityType attribute, no quantityGroup is inserted.
Is it normal ?

Concerning match item, is it possible to conditionate it ?
For exemple, can I write this

Code: Select all

<match elementName="quantity[@quantityType='qty04']" attributeName="quantityTypeSpecifics">
    <items action="replace">
      <item value="d"/>
      <item value="m"/>
      <item value="y"/>
    </items>
  </match>
Thanks,
Regards,
Isabelle

Re: Insert Attribute with value automatically

Posted: Mon Dec 19, 2022 3:04 pm
by alex_jitianu
Hello,
But when I change the value of quantityType attribute, no quantityGroup is inserted.
Is it normal ?
Yes. This is a configuration for content completion so it triggers only for items inserted through content completion. We can look at it as a limitation. We have API which can be used to achieve this use case (this is probably what you did, anyway).
Concerning match item, is it possible to conditionate it ?
In version 24 we've added an alternate element which supports simplified XPath expressions

Code: Select all

<valueProposals path="para[@attr = "value"]"></valueProposals>
Best regards,
Alex

Re: Insert Attribute with value automatically

Posted: Mon Dec 19, 2022 4:50 pm
by Isabelle
Hi Alex,
We have API which can be used to achieve this use case (this is probably what you did, anyway).
Are you talking about AuthorDocumentFilter ?

Regards,
Isabelle

Re: Insert Attribute with value automatically

Posted: Mon Dec 19, 2022 5:02 pm
by alex_jitianu
Hi,
Yes, an AuthorDocumentFilter can be used to intercept such events, as attribute change (AuthorDocumentFilter.setAttribute(AuthorDocumentFilterBypass, String, AttrValue, AuthorElement))

Alex