flibbles / tw5-xml

XML tools for Tiddlywiki5: import/xport, rendering, parsing wth XPath and CSS Selectors
BSD 3-Clause "New" or "Revised" License
10 stars 1 forks source link

Transclusions #2

Closed Wattaged closed 4 years ago

Wattaged commented 4 years ago

Thanks for this flibbles. Is it possible to transclude values into xpath queries? I've tried several ways but no luck. A select seems to transclude the value in but it still doesn't like it.

\define num()<$transclude tiddler="$:/temptest"/>

\define query()/dog[age=$(num)$]/breed

<$select tiddler='$:/temptest'>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='7'>7</option>
</$select>

{{{ [xpath<query>] }}}
flibbles commented 4 years ago

Hmm, yeah. Assembling strings for attributes has always been a hassle in tiddlywiki. Your query macro doesn't get a chance to render the transclude widget before it gets put in. So xpath is getting passed /dog[age=<$transclude tiddler="test"/>]/breed. (The error is showing the wikiRendered version of that, which is misleading, and something I need to fix.)

To get the results you want, try this:

\define query()/dog[age=$(num)$]/breed

<$vars num={{$:/temptest}}>

<$select tiddler='$:/temptest'>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='7'>7</option>
</$select>

{{{ [xpath<query>] }}}

</$vars>

I'll leave this issue open, because I need to fix the xpath error message so it isn't misleading like that.

Wattaged commented 4 years ago

Thanks very much. It works! The interaction between the TW and xpath methods is a mind bender so really appreciate the help. More of these practical examples on the web page would definitely get my vote. Thanks again.

flibbles commented 4 years ago

The "Invalid Query" error message is improved, and an example on creating dynamic queries has been added to the demo site.

Closing issue.