Reference an attribute from nextSibling+1

Out of a list of nodes I want to retrieve the value of an attribute ($Domain) of the nextSibling+1 (same as current node +1)

Here is the code, I use to insert an image linked to the node nextSibling+1

^if(mod($SiblingOrder,4)==1)^
insert …image $Domain
^endif^

How could I retrieve a notes attribute (within the same container) which is equal to of the nextSibling+1?

Thanks for your support in advance.

Just to be sure we’re on the same page, let’s take a concrete example. We have the following notes in a container:

  • Prospero
  • Miranda
  • Ariel
  • Caliban
  • Alonso

How can Miranda’s rule refer to Caliban?

  1. One easy way: Ariel is nextSibling(this), so Caliban is nextSibling(nextSibling(this))
  2. Another way: make a list of the siblings, and use at() to extract the second item from yourself. So
$MyString=$Name(children(parent)).at($SiblingOrder+2)

sets $MyString to Ariel.

1 Like

Once you can’t leverage a ‘pre-built’ designator like nextSibling to use an offset like $Domain(lastSibling), i.e. the sibling is N places before/after your current note, I’d suggest a two stage approach:

  • find the $Path or $ID of the desired note.
  • use the latter value as your offset preference for domain.

For example, let’s say we want an item +3 from here, where we can’t (or shouldn’t) keep nesting designators. For instance:

Stamp code:

var:string vPath;
var:number vOffset;
vOffset = $SiblingOrder + 3;
vPath = collect_if(siblings,$SiblingOrder==vOffset,$Path);
$MyString = $Path(vPath); // only needed for testing
$MyString2 = $Domain(vPath);

Indeed, if the number of displaced places—here 3—were to be variable, you might want to make the above a function where you pass in the desired size of offset. Not in the image above, there is no result for ‘fly’ and later as there is no sibling 3 beyond themselves. Depending on the task’s importance, you might want to add code to test is such a sibling exists and only run the full code if it does. But this gives a general idea.

My test doc (using v9.5.2): sibling-offset-ref.tbx (134.6 KB)

1 Like

Thanks, I was looking for nextSibling(nextSibling(this)).

In my case I have 64 notes in 1 container.

To take your example when I print “Prospero-Note” as a headline before I need to print the image assigned to “Ariel-Note”.

^value($Domain(nextSibling(nextSibling(this))))^.png

This now works perfectly.

Thank you very much and have a great day.

Great and I hope I wasn’t suggesting the first suggested solution wouldn’t work—which of course it does.

While, I’m waiting for a call to start I extended things a bit with 2 functions. The first replicates the earlier stamp, but using a function. In the second, a more generic method, we pass a numeric offset (e.g. a sibling +4 from us. Here are the functions:

function getOffsetDomain(iOffset:number){

var:string vPath;
var:number vOffset;
vOffset = $SiblingOrder + iOffset;
vPath = collect_if(siblings,$SiblingOrder==vOffset,$Path);
$MyString = $Path(vPath);
$MyString2 = $Domain(vPath);

} // END

function giveOffsetSiblingPath(iOffset:number){

var:string vPath;
var:number vOffset;
vOffset = $SiblingOrder + iOffset;
vPath = collect_if(siblings,$SiblingOrder==vOffset,$Path);
return vPath;

} // END

Extra stamps are provided to test each function. Note that you can’t use a function call as a direct offset value, i.e.:

$MyString2 = $Domain(giveOffsetSiblingPath(4)); // FAILS - do not use

In that case we need to capture the function output in a variable:

var:string vPath = giveOffsetSiblingPath(4);
$MyString2 = $Domain(vPath);

I also added a stamp that uses a negative (-2) offset, i.e. for a sibling 2 places lower (i.e. before the current) in the sibling order.

For @Gernot 's original problem, this is unneeded complication. But for later readers, I though it provides a nice example of taking a fixed pattern and making it into a variable one.

Note: this is a simple demo. i’m not doing things like checking if a note exists at the desired offset and just relying on the defaults working in my favour (i.e. an unset empty string remains empty). For real work one might consider safe-guards , e.g. some enclosing conditional test. But, I hope you get the general point about how we can work out sibling offsets.

Indeed, consider a scenario where for whatever reason the desired distance of offset is it self a variable - the outcome of some other calculation. That variable can be passed into the function instead of a literal number.

Here’s the updated TBX: sibling-offset-ref2.tbx (319.3 KB). There is no ‘read me’ - this post is it!

I am doing exactly this to create slide navigation in TBX.

Here is the code of my slide template.

^action(

var:number vThisNote=$OutlineOrder;
var:number vNextNote=$OutlineOrder+1;
var:number vPreviousNote=$OutlineOrder-1;

var:number vPreviousNoteID=$ID(find($OutlineOrder==vPreviousNote));
var:number vNextNoteID=$ID(find($OutlineOrder==vNextNote));

if($IsYesListChildren==true|$IsNoShowTitle(previous)==true){vPreviousNoteID=$ID(previousSibling)};
if($IsYesListChildren==true|$IsNoShowTitle(next)==true){vNextNoteID=$ID(nextSibling)};



var:string vChildrenList=fListChildrenAdv($ID);
var:string vMediaID=collect_if(children,$Prototype=="pMedia",$ID);


)^

<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
	<title>^title^</title>
<style type="text/css">
       ^text(^value($CSSStyle))^
</style>
	
</style>
</head>
<body>
<span style="color:#fff;font-size:small;float:right">
	^if($PresName(TBXConfigNote))^
			^if($IsTitle=true)^&nbsp;
				^else^^value($PresName("TBXConfigNote"))^</span>
			^endif^
		^else^
			^action($MyString=$Name(parent);)^^value($MyString)^
	^endif^
</span>
<br><br>

<h1>^title^</h1>
^text^
^if($IsYesListChildren==true)^^value(vChildrenList)^^endif^
^include(^value(vMediaID)^,"tMedia2")^
<br>
<br>
<br>
<hr>


<div class="divTable">
	<div class="divTableBody">
		<div class="divTableRow">
			<div class="divTableCellLft">^if($Name(vPreviousNoteID)!="StartPres")^<< ^linkTo(^value(vPreviousNoteID)^)^^else^ ^endif^</div>			<div class="divTableCellCtr">^value($Organization("TBXConfigNote"))^ (c) 2022</div>
			<div class="divTableCellRgt">^if($Name(vNextNoteID)!="EndPres")^^linkTo(^value(vNextNoteID)^)^ >>^else^ ^endif^</div>
		</div>
	</div>
</div>
</body>
</html>
```