Re: [xsl] I love programs that output programs

Subject: Re: [xsl] I love programs that output programs
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 17 Jan 2025 20:29:28 -0000
On 17/01/2025 21:22, Roger L Costello costello@xxxxxxxxx wrote:

Recently I was reading Brian Kernighan's new book on AWK, and it showed a
wicked cool AWK program that outputs an AWK program. Below is the AWK program,
followed by the equivalent XSLT program.

The task is to run some checks on a password file. Here is a sample password
file:

root:qyxRi2uVjrg:0:2::/: jd:1L./v6iblzzNE:9:1:John Doe:/usr/jd: jt:otxs1oToyvMQ:15:1:Jim Thomson:/usr/jt: uucp:xutIBs2hKtcls:48:1:uucp daemon:/usr/lib/uucp:uucico sm:xNqy//GDc8FFg:170:2:Sally Smith:/usr/sm: a!f:aiopaIAjfaI:21:1:Fake Person:/usr/a!f: jv::1:Jules Verne:/usr/jv: ah:dsjkdAJ:34:1:Alexander Hamilton

Fields within each line are delimited by a colon.

The first field is the username. It should be alphanumeric. Check each line
to confirm that its username is alphanumeric.
The second field is an encrypted version of the password. The field should
not be empty. Check each line to confirm that it's not empty.
I won't discuss the other fields.
The third check confirms that each line has 7 fields.



-----------------------------------------------------------------------------
---------------
XSLT/XPath Version

-----------------------------------------------------------------------------
---------------
Format the password file as XML:

<passwds>
     <passwd>root:qyxRi2uVjrg:0:2::/:</passwd>
     <passwd>jd:1L./v6iblzzNE:9:1:John Doe:/usr/jd:</passwd>
     <passwd>jt:otxs1oToyvMQ:15:1:Jim Thomson:/usr/jt:</passwd>
     <passwd>uucp:xutIBs2hKtcls:48:1:uucp
daemon:/usr/lib/uucp:uucico</passwd>
     <passwd>sm:xNqy//GDc8FFg:170:2:Sally Smith:/usr/sm:</passwd>
     <passwd>a!f:aiopaIAjfaI:21:1:Fake Person:/usr/a!f:</passwd>
     <passwd>jv::1:Jules Verne:/usr/jv:</passwd>
     <passwd>ah:dsjkdAJ:34:1:Alexander Hamilton</passwd>
</passwds>


Is that("Format the password file as XML")B  done outside of the XSLT?
You could read in the non XML text with fn:unparsed-text and process it
with fn:tokenize and/or fn:analyze-string, no?

Current Thread