Working with ${selection} in Action / XPath
Posted: Wed Nov 11, 2015 8:44 pm
Dear Forum,
I am configuring Oxygen Author for transcribing and formatting historical texts. The main issue are the formattings (like bold, italic, etcetera). An example:
As you can see, the attribute @rend describes the appearance of the section surrounded by <hi>. Now I am building actions to influence @rend, which work like on/off-switches, e.g. the "italic" action should add <hi rend="italic"> to the current selection or add the token "italic" to @rend if it already exists, or delete it when it is already present, or delete the whole <hi> when "italic" is the only token in @rend.
This works fine, so far. My actions are:
(1) self::hi[@rend='italic']
=> UnwrapTagsOperation on self::hi[@rend='italic']
(within <hi>, unwrap <hi> if @rend contains only "italic")
(2) self::hi[contains(@rend,'italic')]
=> ChangeAttributeOperation on self::hi[contains(@rend,'italic')] with ${xpath_eval(normalize-space(replace(@rend,"italic","")))}
(within <hi>, remove "italic" from @rend if it contains more tokens)
(3) self::hi[not(contains(@rend,'italic'))]
=> ChangeAttributeOperation on self::hi[not(contains(@rend,'italic'))] with ${xpath_eval(normalize-space(concat(@rend," italic")))}
(within <hi>, add "italic" to @rend if it is not present)
(4) ancestor::text and not(self::hi)
=> ToggleSurroundWithElementOperation with <hi rend="italic" xmlns="http://www.tei-c.org/ns/1.0"/>
(in all other cases, surround the selection with <hi rend="italic">)
Now I would like to modify this in a way that works also for nested elements, as in the example above. So the rule would be: Within <hi>, if text is selected, and if @rend does not contain "italic", surround the selection with <hi rend="italic">. This would be before the third action. I could not figure out, though, how to work with the selection; I tried ${selection} in the XPath condition, but it does not evaluate. I would be grateful for every hint.
I am configuring Oxygen Author for transcribing and formatting historical texts. The main issue are the formattings (like bold, italic, etcetera). An example:
Code: Select all
<p>Lorem ipsum dolor sit amet, <hi rend="italic">consectetur <hi rend="bold">adipisici</hi> elit</hi>, sed <hi rend="bold italic">eiusmod</hi> tempor incidunt ut labore et dolore magna aliqua.</p>
This works fine, so far. My actions are:
(1) self::hi[@rend='italic']
=> UnwrapTagsOperation on self::hi[@rend='italic']
(within <hi>, unwrap <hi> if @rend contains only "italic")
(2) self::hi[contains(@rend,'italic')]
=> ChangeAttributeOperation on self::hi[contains(@rend,'italic')] with ${xpath_eval(normalize-space(replace(@rend,"italic","")))}
(within <hi>, remove "italic" from @rend if it contains more tokens)
(3) self::hi[not(contains(@rend,'italic'))]
=> ChangeAttributeOperation on self::hi[not(contains(@rend,'italic'))] with ${xpath_eval(normalize-space(concat(@rend," italic")))}
(within <hi>, add "italic" to @rend if it is not present)
(4) ancestor::text and not(self::hi)
=> ToggleSurroundWithElementOperation with <hi rend="italic" xmlns="http://www.tei-c.org/ns/1.0"/>
(in all other cases, surround the selection with <hi rend="italic">)
Now I would like to modify this in a way that works also for nested elements, as in the example above. So the rule would be: Within <hi>, if text is selected, and if @rend does not contain "italic", surround the selection with <hi rend="italic">. This would be before the third action. I could not figure out, though, how to work with the selection; I tried ${selection} in the XPath condition, but it does not evaluate. I would be grateful for every hint.