Extracting attribute values through XPaths
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 10
- Joined: Fri Apr 26, 2013 3:58 pm
Extracting attribute values through XPaths
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:
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>
-
- Posts: 10
- Joined: Fri Apr 26, 2013 3:58 pm
Re: Extracting attribute values through XPaths
Here's more information to what I'd like to accomplish.
This is my source code:
Through a custom XPath action, I'd like source code to resemble this:
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
This is my source code:
Code: Select all
<metadata>
<category base="Video"/>
<category base="Alarms"/>
</metadata>
Code: Select all
<metadata>
<category base="Video">Video</category>
<category base="Alarms">Alarms</category>
</metadata>
Thank you
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Extracting attribute values through XPaths
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/ ... tions.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/ ... 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
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/ ... tions.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/ ... 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
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service