RE: [xsl] QUESTION

Subject: RE: [xsl] QUESTION
From: bryan.s.schnabel@xxxxxxxxxxxxxx
Date: Mon, 12 Sep 2005 16:45:30 -0700
Hello Juan,

I didn't understand all of the words in your question, but an explanation of
how to impose structure on a flat file might help you.

Here's an explanation of a 1.0 method that's worked well for me.  I make
several generalizations and assumptions.  You would need to tailor the
concept to your situation.

1. When the flat file is a text file without XML structure, the first thing
I do is to create a "placeholder file" that references the flat file, making
it a simple XML file.  Suppose your flat file is "flat-archive.txt."  Create
a placeholder file with the following contents, and call it placeholder.xml.

<!DOCTYPE stuffing [  
<!ENTITY stuff SYSTEM "flat-archive.txt">
  ]>
<stuffing>
 &stuff;
</stuffing>

2. Create an input file to act as a starting point to frame the structure,
with the following contents, and call it in.xml.

<Hello>
 <p>The following lines were flat.  Now they have slight structure.</p>
</Hello>

3. Write your XSLT such that it takes in.xml as the input file.  Then write
a template that uses the document() function on the placeholder.xml file.
Often a simple recursive template will do the trick. Assuming the structure
you want to imply is delineated by commas in the flat file, the following
will create a separate row and cell for each comma delimited string:

<xsl:template match="Hello">
 <html>
  <xsl:apply-templates />
  <table border="1">
   <xsl:for-each select="document('placeholder.xml')/stuffing">
    <tr>
     <td>
      <xsl:value-of select="substring-before(text(),',')" />
     </td>
    </tr>
    <xsl:call-template name="cellFinder">
     <xsl:with-param name="rest" select="substring-after(text(),',')" />
    </xsl:call-template>
   </xsl:for-each>
  </table>
 </html>
</xsl:template>

<xsl:template match="p">
 <h2>
  <xsl:apply-templates />
 </h2>
</xsl:template>

<xsl:template name="cellFinder">
 <xsl:param name="rest" />
 <xsl:choose>
  <xsl:when test="contains($rest,',')">
   <tr>
    <td>
     <xsl:value-of select="substring-before($rest,',')" />
    </td>
   </tr>
   <xsl:call-template name="cellFinder">
    <xsl:with-param name="rest" select="substring-after($rest,',')" />
   </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
   <td>
    <xsl:value-of select="$rest" />
   </td>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

So if the contents of the "flat-archive.txt" contained the body of you
initial question, a table would be constructed with each row consisting of
the strings delineated by commas, like this:

<html>
   <h2>The following lines were flat.  Now they have slight structure.</h2>
   <table border="1">
      <tr>
         <td>
            Hello s
         </td>
      </tr>
      <tr>
         <td> I have a doubt Since I can do from XML</td>
      </tr>
      <tr>
         <td> to read flat Archives</td>
      </tr>
      <tr>
         <td> 
            the idea is to referenciar them and to mapear them (definior its

            structure) but the archives they are flat completely is to say
do not 
            include tags of XML
         </td>
      </tr>
      <tr>
         <td> neither estan structured in jerarquica form but or 
            the information this in each line of text
         </td>
      </tr>
      <td> only separated by abatis thanks
         
      </td>
   </table>
</html>

Sorry that I didn't have time to work something up that specifically solves
your problem.  But maybe this will give you some ideas.

Good luck,

Bryan


-----Original Message-----
From: Juan Pablo Rojas Tovar [mailto:jrojas@xxxxxxxxxxxxx] 
Sent: Monday, September 12, 2005 6:27 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] QUESTION


Hello s, I have a doubt Since I can do from XML, to read flat Archives, 
the idea is to referenciar them and to mapear them (definior its 
structure) but the archives they are flat completely is to say do not 
include tags of XML, neither estan structured in jerarquica form but or 
the information this in each line of text, only separated by abatis thanks

Current Thread