Re: [xsl] bat file creation based on xsl /xml

Subject: Re: [xsl] bat file creation based on xsl /xml
From: "Michele R Combs mrrothen@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 15 Jan 2019 13:52:35 -0000
"dir" has all sorts of optional parameters you can set to customize the output
-- opening a command window and typing bdir /?b will get you a full list
of them.



For example, a batch file in my folder "html_pending" containing this single
line:   dir > list.txt     generates a text file called list.txt that contains
this:



Volume in drive G is DATA

Volume Serial Number is 80F7-BAEC



Directory of G:\LIB\Special Collections\Digital Projects\EAD\html_pending



01/14/2019  04:21 PM    <DIR>          .

01/14/2019  04:21 PM    <DIR>          ..

01/15/2019  08:44 AM                18 aaa_list.bat

01/15/2019  08:44 AM                 0 aaa_list.txt

01/11/2019  02:36 PM            60,282 arents_tour.htm

01/11/2019  02:36 PM            66,594 arents_xmas.htm

01/14/2019  04:16 PM            12,836 british_celanese.htm

01/14/2019  04:21 PM            19,731 fineman_weinshenker.htm

01/07/2019  04:25 PM           655,616 huntington_ah.htm

01/14/2019  04:18 PM            11,875 kay_j.htm

01/08/2019  03:07 PM            29,355 plast_hof.htm

01/14/2019  04:19 PM            12,341 vonbayros_f.htm

01/08/2019  02:22 PM            60,151 wurzburg_g.htm

              11 File(s)        928,799 bytes

               2 Dir(s)   7,891,116,032 bytes free



Using the /B (for bbareb) parameter:   dir /B > list.txt     you get just
the file names:



aaa_list.bat

aaa_list.txt

arents_tour.htm

arents_xmas.htm

british_celanese.htm

fineman_weinshenker.htm

huntington_ah.htm

kay_j.htm

plast_hof.htm

vonbayros_f.htm

wurzburg_g.htm



Using a wildcard you can list only files of a specific file type, so  dir /B
*.htm > list.txt  yields this:



arents_tour.htm

arents_xmas.htm

british_celanese.htm

fineman_weinshenker.htm

huntington_ah.htm

kay_j.htm

plast_hof.htm

vonbayros_f.htm

wurzburg_g.htm







-----Original Message-----
From: Syd Bauman s.bauman@xxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, January 14, 2019 4:41 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] bat file creation based on xsl /xml



Michele may have hit the nail on the head, here, but some other issues are
raised.



0) I don't think the @version and @indent attributes of <xsl:output>

    make much sense when method=text. (And I'll ask that wiser folks

    than me post a correction if I'm wrong on that.)



1) The OP's XSLT is not well-formed. (There is an extraneous end-tag

    for <xsl:variable> lying around.)



2) I'm not 100% sure what `dir` does in Windows, but I'll bet it

    would list the files that end in '.xml'. This program also tries

    to *read* and *parse* those files. So whereas `dir` will happy

    list a file that is not really XML so long as it has a .xml

    extension, this program will entirely fail if any one of the

    files found in the same directory as the XSLT program ends in

    '.xml' but is not well-formed XML. (Which may, of course, be the

    desired behavior. In which case one might be better off using

    `xmlwf`. :-)



3) This program spits out the URL of each selected file, not its

    name (or path & name). On my (GNU/Linux system running Saxon 9

    HE) that means that each file's output line will start with

    "file:". And it also has implications for character escaping

    (i.e., what happens if a space or solidus or whatever is in the

    file's name -- here you get %-sign escaping, but I doubt `dir`

    does that).



4) This program reads in an input file, but then summarily ignores

    it when choosing the directory to list. I can't help but wonder

    if OP wants a list of the .xml files in the same directory as the

    XSLT program (which is what this program gives me when I run it

    w/ Saxon), or would prefer a list of the .xml files in the same

    directory as the input document.



=========

<?xml version="1.0" encoding="UTF-8"?>



<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

  exclude-result-prefixes="#all">



  <xsl:output method="text" encoding="UTF-8"/>



  <xsl:template match="/">

    <xsl:text>&#x0A;----- XSLT program file's directory -----</xsl:text>

    <xsl:for-each select="collection('.?select=*.xml')">

      <xsl:text>&#10;</xsl:text>

      <xsl:value-of select="document-uri(.)"/>

    </xsl:for-each>

    <xsl:text>&#x0A;&#x0A;----- XML file's directory -----</xsl:text>

    <xsl:for-each select="collection( concat( replace( base-uri(/),
'/[^/]+$',''),'?select=*.xml'))">

      <xsl:text>&#10;</xsl:text>

      <xsl:value-of select="document-uri(.)"/>

    </xsl:for-each>

    <xsl:text>&#x0A;</xsl:text>

  </xsl:template>

</xsl:stylesheet>





> If I read this right, it looks like you just want to generate a list

> of the XML files in a directory, is that correct? If youbre in a

> windows enviroment the bdirb command will do what you want.

Current Thread