Re: p:label-elements vs p:add-attribute

Thanks, Martin!

<p:viewport> provides the positional offset of the current context item
through p:iteration-position(), and the size of the viewport, if needed, is
available in p:iteration-size(). I think that's comparable to $p:index with
<p:label-elements>, but perhaps there's a difference that I've overlooked.

After posting (!), I did notice one other difference: <p:viewport> sets a
context that can look only downward, while <p:label-elements> seems to have
access to the entire original document tree. I don't need that greater
scope for my use, but if my understanding is correct, it helps reframe the
question: <p:label-elements> can do something that <p:viewport> together
with <p:add-attribute> can't do (that is, it can construct attribute values
that require looking upward in the tree, but is there something that
<p:viewport> with <p:add-attriibute> can do that <p:label-elements> can't
do? Perhaps the answer is that there isn't when they're used together, but
<p:viewport> has other uses that don't involve adding attributes and we may
have a need to add attributes in a context that we don't access with
<p:viewport>.

Thanks again,

David

On Wed, Feb 5, 2025 at 5:38 PM Martin Honnen <martin.honnen@gmx.de> wrote:

>
> On 05/02/2025 23:01, David Birnbaum wrote:
> > Dear XProc-dev,
> >
> > I'm still learning my way around XProc, and to add unique identifier
> > attributes to specific elements in a document within a pipeline I used
> > <p:viewport> to match the elements I cared about and <p:add-attribute>
> > (using p:iteration-position()) to create and add the unique
> > identifiers. I was pleased with the result until I stumbled today over
> > <p:label-elements>, which I hadn't noticed / known about earlier, I
> > see that <p:label-elements> has a "replace" option that
> > <p:add-attribute> lacks, but otherwise it looks as if the two methods
> > can be used for the same purpose.
> >
> > Are there situations (other than where I need to control whether to
> > replace an existing value) where one method should be preferred over
> > the other? That is, what types of use-cases motivated the decision to
> > make both methods available in the language? Thanks for any guidance!
> >
>
> Perhaps one advantage that p:label-elements gives you is that positional
> index variable "An additional variable $p:index is available that holds
> the index (sequence number) of the match" exposed in the "label"
> expression.
>
>
>

Received on Wednesday, 5 February 2025 22:58:08 UTC