- From: <denis.maier@unibe.ch>
- Date: Fri, 22 Nov 2024 12:01:30 +0000
- To: <ndw@nwalsh.com>
- CC: <xproc-dev@w3.org>
> -----Ursprüngliche Nachricht----- > Von: Norm Tovey-Walsh <ndw@nwalsh.com> > Gesendet: Freitag, 22. November 2024 10:03 > An: Maier, Denis Christian (UB) <denis.maier@unibe.ch> > Cc: xproc-dev@w3.org > Betreff: Re: Conditional processing based on option > > > But, apparently this does not work as p:with-input is not allowed under > p:when and p:otherwise. > > You have to put the whole step in the when/otherwise branches. > This should work, though I haven’t tested it :-) Unfortunately it doesn't. Error in XPath expression 'c:file/@name': Context item is needed, but not provided: 11 items found. > > <p:option name="sorted-files" select="'true'" /> > > <p:choose> > <p:when test="$sorted-files = 'false'"> > <p:identity> > <p:with-input select="//*:file => sort((), function($file) { analyze-string > ($file!@name, '[0-9]+')!descendant::*[not(*)]!(if (. > instance of element(fn:match)) then number(.) else string(.)) })"/> > </p:identity> > </p:when> > <p:otherwise> > <p:identity> > <p:with-input select="//*:file"/> > </p:identity> > </p:otherwise> > </p:choose> > > > Is there a way to make this work? > > Martin showed another alternative, using a larger and more complex XPath > expression. That will work too. I tend to think of XProc pipelines in terms of > step composition, so I prefer to have more smaller steps rather than fewer > steps with more complex XPath expressions. YMMV. Martin's solution works indeed. So I can well use that one, but I'd still be interested in learning why the solution above fails. > > When I was first reading this thread, I thought, I wonder if we need a p:sort > step. Fun challenge: can you implement a generalized sort step in XProc? You > can certainly do it with p:run, but can you do it without p:run? > Yeah, a p:sort sounds like a good idea, and I was perplexed to see that it doesn't exist. (Appararently, ChatGPT also thinks that such a step already exists, as well as p:log and p:message.)
Received on Friday, 22 November 2024 12:01:36 UTC