[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

FAQ candidate? parsing line-separated text files (was: Re: O

Subject: FAQ candidate? parsing line-separated text files (was: Re: Off-topic: DOS script for XML directory listing)
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Wed, 01 Mar 2000 23:12:28 +0000
parsing line
This is a pure DOS / XML / XSLT way of creating an XML file containing
directory listing. It's based on my earlier solution which didn't
tolerate embedded spaces in filenames.

The solution now takes a line-separated text file and processes it into
an XML file. Doing this requires two uses of XML entities, firstly a
system entity to read the text file into the content of an XML element;
and secondly a character entity to access the acii 10 linefeed character
to parse that content. 

For anyone unfamiliar with system entities, run the xmlDir.bat, then see
the difference between looking at xmlDir.xml in a text processor and in
an xml processor like IE5. Ta-da...

I was never very fond of XML entities so this was a useful exercise for
me, I hope it helps others too.

Francis.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<!-- root function -->
<xsl:template match="/xmlDir">

  <!-- create our root output element -->
  <xmlDir>
  
    <!-- the path is on the first line, filenames on the others -->
    <xsl:call-template name="file">	
      <!-- all the CR-LF pairs have been normalised to ascii 10, as specified in
	    http://www.w3.org/TR/1998/REC-xml-19980210#sec-line-ends
      -->
      <xsl:with-param name="path" select="substring-before(string(), '&#10;')" />  
      <xsl:with-param name="flist" select="substring-after(string(), '&#10;')" />  
    </xsl:call-template> 

  </xmlDir>

</xsl:template>


<!-- process the individual files in the space-separated file list -->
<xsl:template name="file">
  <xsl:param name="path" />
  <xsl:param name="flist" />

  <xsl:if test="$flist != ''">

    <!-- output the path and the first filename as one element -->
    <xmlFile><xsl:value-of 
	            select = "concat($path, '\', substring-before($flist, '&#10;'))" 
              /></xmlFile>

    <!-- now recurse with same path and rest of the filenames -->
    <xsl:call-template name="file">
      <xsl:with-param name="path" select="$path" />
      <xsl:with-param name="flist" select="substring-after($flist, '&#10;')" />
    </xsl:call-template>

  </xsl:if>

</xsl:template>

</xsl:stylesheet>    
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xmlDir [
<!ENTITY xmlDirList
           SYSTEM "xmlDir.lst">    
  ]>

<xmlDir>&xmlDirList;</xmlDir>

Attachment: xmlDir.bat
Description: application/unknown-content-type-batfile

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.