Need validation or workaround of selected content in XPath Activation

Oxygen general issues.
larsS
Posts: 18
Joined: Mon Sep 13, 2021 10:41 am

Need validation or workaround of selected content in XPath Activation

Post by larsS »

Dear masterminds,

I have the following problem, I would like to prevent that the ToggleSurroundWithElement operation creates empty elements when there is no text in the current element and no text | text() node is selected. In the schema, via restrictions in the XSD, elements with no content are also already set as errors. schemaAware is set as true.

1. There is no oxy:current-selected-content() (like here suggested) and oxy:selected-elements() as well as oxy:current-selected-element() access only the direct parent, because element(). But I need a way to interpret the selected text() node. But maybe I did not understand that oxy:selected-elements() maybe works different, but the example doesn't help.

2. Here is the a shorted XSD schema for the necessary element. Maybe there is the error here, so that's why the schemaAware principle doesn't work.

Code: Select all

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
  vc:minVersion="1.1" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="hi" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="NonEmptyString">
                <xs:attribute name="rend" use="required">
                  <xs:simpleType>
                    <xs:restriction base="xs:string">
                      <xs:enumeration value="italic"/>
                      <xs:enumeration value="bold"/>
                      <xs:enumeration value="underline"/>
                      <xs:enumeration value="superscript"/>
                      <xs:enumeration value="subscript"/>
                    </xs:restriction>
                  </xs:simpleType>
                </xs:attribute>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="NonEmptyString">
    <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
      <xs:pattern value="[^\s]?"/>
      <xs:pattern value="[^\s].*[^\s]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>
4. I tried something like ./string() ne '', but then the activation reports back that the operation is not valid. Is it possible that I can act in the XPath activations not on content but only on the element level.

5. Is there any other way than 1. and 2. to control the operation via XPath activation. But I would not like to write XQuery statement with external paramter oxy:selection for all actions. Which is an absolute fallback solution.

Thank you very much.

Best Regards
Lars
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: Need validation or workaround of selected content in XPath Activation

Post by alex_jitianu »

Hi Lars,

The schemaAware flag checks only if the inserted element is valid in the insert location, it doesn't do any validation withing the inserted fragment itself. Yes, we had an earlier request for a oxy:current-selected-content() externsion function, but we didn't manage to implement it yet. I'll add your vote for it and I'll increase its priority.

As a workaround, you could implement a custom ToggleSurroundWithElementOperation operation that makes this check and presents an error message to the user. I can send you the source code for the built-in operation to get you started if you write me an email on support@oxygenxml.com. If I get a little free time, I'll try to send send you a modified version that does what you want.

Best regards,
Alex
Post Reply