Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-07-02 18:55:16

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

evaluate and XPATH string-length

Code

<txp:variable name="page_date"><txp:page_url type="month" /></txp:variable>
[<txp:variable name="page_date" />]-
[<txp:evaluate query='string-length( <txp:variable name="page_date" /> )' />]

Output

[2016]- [4]
[2016-06]- [4]
[2016-06-14]- [4]

I wasn’t expecting 4 every time. Is there anything obvious I am doing wrong?

Edit: I’ve made some progress. The variable isn’t actually getting passed to the XPath function – instead it is seeing “1996” every time.

Offline

#2 2020-07-02 19:56:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: evaluate and XPATH string-length

Does it make a difference if you enclose the <txp:variable name="page_date" /> inside the string-length function with quotes (single or double – but you’ll need the two-singles trick if you choose the former) to indicate it’s a string?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2020-07-02 20:20:22

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: evaluate and XPATH string-length

Bloke wrote #324216:

Does it make a difference if you enclose the <txp:variable name="page_date" /> inside the string-length function with quotes (single or double – but you’ll need the two-singles trick if you choose the former) to indicate it’s a string?

I literally just figured it out.

[<txp:evaluate query=' string-length( "<txp:variable name=''page_date'' />"  )' />]

Offline

Board footer

Powered by FluxBB