Subject: Re: [xsl] How to express this in XPath: "when condition do action" where condition cannot be evaluated until data arrives later From: "BR Chrisman brchrisman@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 20 Dec 2022 01:33:40 -0000 |
if these are a static set of files in a directory, then what you are doing is joining the cars-observed database/table with the stolen-cars database/table. I would make a single file out of the cars-observed files like in bash: ( echo "<Observed>"; trap 'echo "</Observed>"' EXIT; cat /path/to/files/wildcard*.xml ) | xslt style-sheet.xsl - then in style-sheet.xsl lookup/reference the cars in the stolen-db with document('/path/to/stole/cars/list')//Car[LicensePlate... If you're instead trying to take a sequence of xml files and run an xpath expression *only* on them 'as they come in', I'd join each observed xml file with the stolen db. while read observedFileName; do ( echo "<Cars>"; trap 'echo "</Cars>" EXIT; cat $observedFileName stolen-cars.xml; ) | xmllint --xpath 'count(/Cars/Car[LicensePlate=/Cars/PoliceReports//LicensePlate]) > 0' - | grep -qsx true && echo "$observedFileName has a stolen car in it!" done (would actually output xml from there, but it's probably better to invoke xslt at that point..) if it needs to be mechanized in some old-school batch processing type system, I'd use 'inotifywait' to trigger on non-empty directory.. (I think there are probably 1.5 people in the world who use xmllint (libxml2) on the linux/bash cmdline a lot...) On Mon, Dec 19, 2022 at 10:45 AM Roger L Costello costello@xxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Hi Folks, > > I have an XSLT program that processes XML files in a folder. Some of the > XML documents contain data about a car, like this: > > <Car> > <Make>Toyota</Make> > <Model>Avalon</Model> > <LicensePlate>12345</LicensePlate> > </Car> > > At some point the XSLT program reads in that XML document and begins > processing it. The objective of processing is to output the license plate > number if the car is stolen and "" (not stolen) otherwise. However, the > document does not contain the necessary information to make that decision. > The information to make the decision arrives some time later, in another > document: > > <PoliceReport> > <Car> > <LicensePlate>12345</LicensePlate> > <Status>Stolen<Status> > </Car> > </PoliceReport> > > So the desired processing behavior is this: > > Read the next XML document. > If the XML document contains data about cars then > Wait until the police report arrives .... > .......... time elapses ........... the police > report arrives: if it says the car is stolen > then output "stolen" else output "" > > I want to express that! > > And, I want to express it, not in an XSLT program, but in a single XPath > expression! > > The UNIX shell has an analogous functionality that I describe now. The > "trap" command can be added into a shell program. The command has this form: > > trap command signal > > It has this meaning: During execution of the shell program, if 'signal' is > received, then execute 'command'. > > Here's an example to illustrate how it may be used ('2' is the signal for > the user pressing Ctrl+c; i.e., for the user terminating the program): > > trap "rm WORKDIR/file; exit" 2 > > That means: If the program is suddenly terminated (by the user pressing > Ctrl+c), remove 'file' from the WORKDIR folder and then exit. > > I want that kind of functionality! In XPath! > > Is it possible to achieve that functionality using XPath? Or is this > outside the realm of XPath capabilities? > > /Roger > > For my own notes: > > Potentially relevant information: > > Michael Kay Balisage paper: Asynchronous XSLT > > > https://www.balisage.net/Proceedings/vol25/html/Kay01/BalisageVol25-Kay01.html > > Xalan-J Thread.sleep() function: all links I followed failed. Still > available? > > Java Sleep() function: > https://www.geeksforgeeks.org/thread-sleep-method-in-java-with-examples/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to express this in XP, Martin Honnen martin | Thread | [xsl] Re: How to express this in XP, Roger L Costello cos |
Re: [xsl] How to express this in XP, Martin Honnen martin | Date | [xsl] Re: How to express this in XP, Roger L Costello cos |
Month |