Question

I'm working with a system (Maximo) that generates a text file.
I need to remove just the first line of the file.
The way to do that should be using XSLT.

Any idea?

Was it helpful?

Solution

Yes, you can accomplish what you want in XSLT!

It would probably be easier to do so in XSLT 2.0, if that is an option for you. Michael Kay answered a similar question on the XSL mailing list in 2005.

Paraphrasing 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 that it's an XML external entity, and referencing it from an XML document that causes the entity to be expanded.

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

OTHER TIPS

The way to do that is not using XSLT.

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

XSLT will only take a valid XML file as input, not a general text file. It can output text, though.

(I use XSLT to generate C code, for example.)

If your XSLT processor supports any-to-any transformation(binary xforms via FFDs - Flat File Descriptors), there is a possibility of doing this. You can wrap your text in a node and then operate on that node using a regular XSLT template to output whatever is after the first carriage return.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top