Extracting attribute values through XPaths

Questions about XML that are not covered by the other forums should go here.
fabdf
Posts: 6

Extracting attribute values through XPaths

Wed Apr 02, 2014 6:36 pm

Hi,

I'd like to create an action button that extracts the value of a specific attribute (the "base" attribute in this case), and automatically inserts this value as text in a specific element (the <category> element). Preferably, this action can occur as soon as a value is selected for the base attribute, but we can also have it so that once the value is selected, pressing a button automatically populates the <category> element with the correct value.

In the example below, I'd like the two category elements to contain the "Video" and "Alarms", without having to enter these values manually. Our values for the "base" attribute are defined in a subject scheme map that is included in the bookmap.

Any ideas on how we can go about this? Which XPath expressions should we use?

Thank you

Example code:

Code: Select all

 <metadata>
      <category base="Video"/>
      <category base="Alarms"/>
      <keywords>
        <indexterm>video</indexterm>
      </keywords>
    </metadata>
  </prolog>
fabdf
Posts: 6

Re: Extracting attribute values through XPaths

Thu Apr 03, 2014 5:13 pm

Here's more information to what I'd like to accomplish.

This is my source code:

Code: Select all

    <metadata>
    <category base="Video"/>
    <category base="Alarms"/>
    </metadata>

Through a custom XPath action, I'd like source code to resemble this:

Code: Select all

  <metadata>
  <category base="Video">Video</category>
  <category base="Alarms">Alarms</category>
  </metadata>

So, through an XPath custom action that comes bundled with Oxygen, I'd like the character element to take the value that is assigned to the "base" attribute. I've used the "base" attribute in my example, but it can be any other attribute. Isn't there an expression I can use to have an element take the same value given to a specific attribute for that element?

Thank you
Radu
Posts: 5221

Re: Extracting attribute values through XPaths

Mon Apr 07, 2014 12:05 pm

Hi,

Sorry for the delay.

None of our default Author operations we provide out of the box cannot be used for what you want:

http://www.oxygenxml.com/doc/ug-oxygen/#topics/dg-default-author-operations.html

For Oxygen 16.0 (in a couple of months) we are working to add a special "xpath_eval" editor variable which in principle could be potentially used with an InsertFragmentOperation to insert a certain text to an element by using the attribute value defined in some place else in the XML document.

As an alternative if you are a Java developer or have a Java developer in your team you can use our Author SDK:

http://www.oxygenxml.com/doc/ug-oxygen/#topics/author-devel-guide-intro.html

to create your own custom Java-based Author Operation (extending "ro.sync.ecss.extensions.api.AuthorOperation") and use our extensive API to read the attribute value from the desired element and insert it as text in another or in the same element.

Could you give me more details about your use case?
What you are trying to do seems to be redundant, duplicating the same content in several places in the XML. Why don't you do an XSLT customization so that the XML remains with the values in only one place but the XSLT processing interprets them as if they would also be in the element's text value?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 1 guest