Xpath: Choosing the parent node value in xpath when a child node is present

Trying to generate an HTML table using JavaScript based on XML data.

When a child element like //host exists, I need to extract the value of a parent element called "name" from a different ancestor using XPath

The required channel name can be found in this XPath expression:

"/serverConfiguration/channels/channel/name"

This should only be done if the child element is located at:

"/serverConfiguration/channels/channel/sourceConnector/properties/listenerConnectorProperties/host"

Ensure the existence of the child element before extracting the channel name.

Answer №1

When it comes to XPath, all you need is a predicate like

/serverConfiguration/channels/channel[.//host]/name
or
/serverConfiguration/channels/channel[sourceConnector/properties/listenerConnectorProperties/host]/name
.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Enhance your website with autocomplete feature using the power of jQuery 1.4.2 and jQuery UI 1

Struggling to make jQuery autocomplete work. Despite searching for examples, most seem outdated. Modeled after a good example from the jQuery UI site but still can't get it to display data. My JSON data source is accessed via URL. [{ "pk": 1, "mo ...

The issue of empty data in Symfony 3 Form Ajax Post Requests

Displaying a list of tags with the option to add more dynamically. Using Ajax instead of Symfony Doctrine for form submission to allow dynamic updates without page reloads. This is how the form is structured in HTML: <div class="tag-form" ...

Vue Js: Creating an array of checkboxes

I have a collection of checkboxes sourced from the main system object where I store all system settings (referred to as getSystem{}). Within this form, I am retrieving information about a User, who possesses an array of roles []. How can I cross-reference ...

React Router Error: Hook call invalid. Remember to only use hooks inside the body of a function component

I am having an issue with my React app that uses react router. In Box.js, I am attempting to access the URL parameters but I am encountering the following error message: Invalid hook call. Hooks can only be called inside of the body of a function component ...

What is the method for showing all properties of a JavaScript array/object in the Chrome browser?

When it comes to JavaScript, there is a surprisingly confusing distinction between arrays and objects as well as array-like objects: var a = []; // empty array, right? a.foo = 'bar'; // a is also an object The issue arises when inspecting var ...

Leveraging the power of promises to handle multiple requests

Recently, I encountered an issue while trying to use the request-promise module to check multiple websites simultaneously. When using Promise.all as intended, the promise would return with the first rejection. I sought a better way to execute multiple requ ...

Is it possible to update the version of NPM?

Having an issue with installing packages for my React-Native project due to a NPM version error. How can I upgrade it? Currently using version 4 ...

Problem with bcrypt npm installation on Mac OS X 10.9 and Node v0.10.22

Operating System Information: Mac OS X 10.9 Node version: v0.10.22 An error occurs when attempting to install the bcrypt package. Any suggestions on how to resolve this issue? Any assistance would be highly appreciated. > [email protected] install /U ...

How can I position 7 images absolutely within a specific div?

I've been working on a website where users can have their avatars displayed using a JS function that loads 7 different images onto the page. These images correspond to different elements such as skin base, hair, eyes, mouth, shirt, shoes, and pants, a ...

Guide for Uploading, presenting, and storing images in a database column with the help of jQuery scripting language

What is the best method for uploading, displaying, and saving an image in a database using jQuery JavaScript with API calls? I am working with four fields in my database: 1. File ID 2. Filename 3. Filesize 4. Filepath ...

Change the behavior of an onclick event on the second click

I'm trying to make a button on my website that not only plays music when clicked but also changes the text inside the button to "Go to SoundCloud" and redirects to SoundCloud. Currently, I have been able to achieve both functions separately - redirect ...

What is the best way to define the entry points for all files in tsup/typescript that compile into the root dist

In my TypeScript project, I am utilizing the tsup build tool for bundling. I have a requirement to specify all the folders and files within the components directory to the root dist folder. src/ components/ card/ card.tsx ...

Ajax fails to transmit information

Currently, I am in the process of familiarizing myself with the usage of ajax. An issue that I am encountering is that clicking a submit button in a form does not effectively send data. Below you can find the JQuery code I am using: $('input[name=" ...

What advantages does insertAdjacentHTML() offer compared to similar jQuery functions?

As a beginner in JS/jQuery, I recently stumbled upon this resource advocating for the use of vanilla JS over jQuery. When considering functions like insertAdjacentHTML() versus .before() or .append(), is there a valid argument for choosing one over the o ...

Tips for preventing the use of website URLs as variables in jQuery ajax() calls:

Having some trouble. For example: $(document).ready(function () { $("#btnSend").click(function () { var noti_p = { url: "Pusher_Controller.ashx", data: "&appname=" + $("#selt1").val() + "&title=" + $("#title"). ...

Running multiple controller functions in nodejs can be achieved by chaining them together in the desired

Currently, I am working on the boilerplate code of mean.io and adding a password reset email feature to it. Whenever a user requests a password reset with their email as a parameter, I generate a unique salt (resetid) and send them an email with a link con ...

Unable to retrieve the desired dropdown element using xpath location strategy

On my website, I have a drop-down menu for selecting time zones and I need to be able to access the options easily. https://i.sstatic.net/jR4gx.png Here is the HTML code snippet: <li> <div id="ember2503" class= ...

What sets class/instance methods apart from static methods when it comes to their functionality in applications?

As I develop APIs for my application, I've been curious about the difference between defining functionality methods like this: class Foo { static method1(req, res) {} static method2(req, res) {} } and class Foo { method1(req, res) {} method ...

Minimize duplication of HTML code by refraining from PHP usage

It seems like this task may be simple for some individuals. To prevent redundancy in code across multiple pages, my goal is to insert segments of HTML code without having to manually input all of the elements each time. It's similar to a page controll ...

Start the Express server by utilizing Grunt

Can anyone assist me with adding a task to my Gruntfile that will start my Express server instead of the default one? I attempted to create a task and use require("server.js"), but it doesn't seem to be working properly. When I run "grunt mytask", the ...