Remove first line from text file using XSLT

I am working with a system (Maximo) that generates a text file.
I only need to delete the first line of the file.
The way to do this is to use XSLT.

Any idea?

+2


source to share


4 answers


Yes, you can accomplish what you want in XSLT!

In XSLT 2.0, it would be easier to do this if that's the option for you. Michael Kay answered a similar question on the XSL mailing list in 2005.

To paraphrase his answer, with small examples:

In XSLT 2.0 : you can use the unparsed-text () function to read the file, tokenize () to split it into lines (and just ignore the first line).



<xsl:for-each select="tokenize(unparsed-text($in), '\r?\n')">
 ...
</xsl:for-each>

      

In XSLT 1.0 : You can read a flat text file by pretending to be the XML of an external object and referencing it from an XML document that calls the object to be expanded.

<!DOCTYPE foo [
<!ENTITY bar SYSTEM "bar.txt">
]>
<foo>
&bar;
</foo>

      

+4


source


The way to use is not with XSLT.



XSLT can create text files, but cannot process text files. It can only process well-formed XML.

0


source


XSLT will only accept a valid XML file as input, not a regular text file. It can output text.

(For example, I am using XSLT to generate C code.)

0


source


If your XSLT processor supports any transformation (binary xforms over FFDs - flat file descriptors), there is a way to do that. You can wrap the text in a node and then work with that node with a regular XSLT template to output what is after the first carriage return.

0


source







All Articles