Link to an href

frodos_pants
Posts: 4

Link to an href

Fri Jan 13, 2017 7:55 pm

Is there a way to generate an id, and populate the href through an action? And if so, is there a way to differentiate cases where you have multiple section with the same class as with "topic" in the example below?

My tagging fragment looks like this:

Code: Select all

<section class="topic" id="${id}" xmlns="http://www.w3.org/1999/xhtml">
  <header>
    <h1 class="title"><a href="#${xpath_eval(//section[@class='topic']/div[@class='toggleable']/@id)}" class="toggle">Searching for answers</a></h1>
  </header>
  <div class="toggleable" id="${id}">
    <p><a href="#${xpath_eval(//section[@class='topic']/div[@class='toggleable']/@id)}" class="toggle-close">close</a></p>
  </div>
</section>

When I run this, the id generates, but the xpath doesn't populate the href, below is what the action places:

Code: Select all

<section class="topic" id="ops_ddd_py">
            <header>
              <h1 class="title"><a href="#" class="toggle">Searching for answers</a></h1>
            </header>
            <div class="toggleable" id="pps_ddd_py">
              <p><a href="#" class="toggle-close">close</a></p>
            </div>
          </section>

I'm using the xhtml framework. Any thoughts? Please let me know if you need more information to answer this question.

Thanks,
Tom
Radu
Posts: 5089

Re: Link to an href

Mon Jan 16, 2017 12:26 pm

Hi Tom,

Unfortunately your approach does not work, the entire XML fragment is inserted at once so the xpath_eval is not evaluated over the content with the fragment inserted.
I think that you first need to define 2 Author actions:

1) The first action uses the InsertFragmentOperation to insert an XML like this:

Code: Select all

<section class="topic" id="${id}" xmlns="http://www.w3.org/1999/xhtml">
  <header>
    <h1 class="title"><a href="#${xpath_eval(//section[@class='topic']/div[@class='toggleable']/@id)}" class="toggle">Searching for answers</a></h1>
  </header>
  <div class="toggleable" id="${id}">
    <p><a href="#PLACE_HOLDER_ID_HERE" class="toggle-close">close</a></p>
  </div>
</section>


so it inserts some kind of pattern in the @href value, pattern which will later be replaced by:

2) The second action uses the ChangeAttributeOperation which can locate the proper element using the xpath location and change its value to a value computed using xpath_eval.

So if all goes well. if you invoke both actions one after the other you would get your expected result.
Then:

3) You create a third action using the ExecuteMultipleActionsOperation exemplified here:

https://www.oxygenxml.com/doc/versions/18.1/ug-editor/topics/dg-default-author-operations.html

So your third action should call the first 2 actions one after the other.
Then on the toolbar/menus you can mount only the third action.

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

Return to “XHTML”

Who is online

Users browsing this forum: No registered users and 0 guests