• « Interesting possibilities exist -- and they existed over [see text] here first
    • |
    • Main
    • |
    • XSLT 2.0, XQuery, and their non-support on the .NET platform »
            • December 15, 2004

              Accessing raw text files using XSLT 1.0

            • Every once and a while someone will post a question to XSL-List in regards to accessing non-XML files and using them in a transformation. While its impossible in XSLT 1.0 to directly access non-XML text files heres a trick that David Carlisle recently posted to yet another question on this subject:

              --

              > I need my xsl reads a txt file, like this:
              

              XSL1 can only read XML files, although you can easily make an xml file wrapper around your text if you have a file.txt that you know doesn't have any < or or > & characters in it then you can make a file.xml that looks like

              <!DOCTYPE vector [
              <!ENTITY x SYSTEM "file.txt">
              ]]>
              <vector>&x;</vector>
              

              then in your xslt you can go

              <xsl:copy-of select="document('file.xml')"/>
              

              and will get

              <vector>
              10101010101010101111010101010
              10101011100001010101010101010
              00011010101010101010101011011
              </vector>
              

              as the result.

              -- In follow up Michael Kay adds:

              In 2.0 it's simply:

              <vector>
               <xsl:value-of select="unparsed-text('file.txt')"/>
              </vector>
              

              --

              Related to this topic, special character handling in XSLT is something that is not very well understood. A fantastic reference on this subject was created by Dave Pawson and can be found within his excellent XSL FAQ

              And to close up this post: Encoding happens to be one of the current topics over on UnderstandingXSLT.com in which Jeni Tennison has posted a lot of valuable insite and related links. If you haven't had a chance to add the XML feed of your choice to your reader here is the Atom, RSS 1.0(RDF), and RSS 2.0 feed.

            • Posted by m.david : December 15, 2004 05:30 AM GMT

            Trackback Pings

            TrackBack URL for this entry:
            http://www.xsltblog.com/xslt-blog-mt/mt-tb.cgi/179

            Listed below are links to weblogs that reference Accessing raw text files using XSLT 1.0:

            » Links from LeXRus

            [textile]
            _**For exchange links, you need to send a message to "My Google Group":http://groups-beta.google.com/group/lexrus or post a comment to this node.**_

            *My websites*

            * "Blueidea XML News Aggregator":http://blog.blueidea.com

            [Read More]

            Tracked on December 22, 2004 07:49 PM

            » Home Equity Loan from Home Equity Loan
            Home Equity Loan [Read More]

            Tracked on March 4, 2006 03:30 AM

            » Real Estate Investing from Real Estate Investing
            Real Estate Investing [Read More]

            Tracked on March 5, 2006 03:25 AM

            » Beauty from Beauty
            Beauty [Read More]

            Tracked on March 6, 2006 01:02 AM

            » Life Insurance from Life Insurance
            Life Insurance :: Life Insurance is a niceblog. [Read More]

            Tracked on March 11, 2006 07:52 PM

            » Loans from Loans
            Personal Loans [Read More]

            Tracked on March 15, 2006 10:05 AM

            » free blackjack from free blackjack
            You free blackjack ? [Read More]

            Tracked on March 17, 2006 05:15 AM

            Comments

            Post a comment




            Remember Me?

            (you may use HTML tags for style)

          • © 2005 :: <XSLT:Blog/> (xsltblog.com) is a product of M. David Peterson and FunctionalX Consulting. See Licensing Info Below.
          • Except where otherwise noted, this sites content and source code is licensed under the Attribution License from Creative Commons.