2

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?

zx485
  • 28,498
  • 28
  • 50
  • 59
NitroxDM
  • 5,039
  • 10
  • 44
  • 56

4 Answers4

4

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>
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
0

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.

Ben Blank
  • 54,908
  • 28
  • 127
  • 156
  • The way to do that is not using XSLT. -- Agreed but right now it's the only viable option. – NitroxDM Sep 18 '09 at 21:27
  • @NitroxDM — That's what each of the answers here is trying to say — *if XSLT is the **only** tool you have, it cannot be done*. You **must** involve some other tool to accomplish your goal, and if you can involve another tool at all, then you have an avenue to use something more appropriate than XSLT. – Ben Blank Sep 18 '09 at 22:33
  • @Ben Blank - An XSLT solution IS TOTALLY possible. See my answer. – Mads Hansen Sep 19 '09 at 13:46
0

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.)

0x6adb015
  • 7,473
  • 4
  • 24
  • 38
  • XSLT 2.0 can process non-XML files using the unparsed-text() function and XSLT 1.0 can be tricked into working with plain text by using it as an entity reference. – Mads Hansen Sep 19 '09 at 13:49
0

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.

Thiyagaraj
  • 3,585
  • 1
  • 18
  • 15
  • Could one wrap the contents of the text file into a node using XSLT? – NitroxDM Sep 18 '09 at 21:24
  • @NitroxDM — Catch-22. If a file needs to be processed before you can use it with XSLT, you cannot use XSLT to do that processing. – Ben Blank Sep 18 '09 at 22:35
  • Depending on your processor/platform - WebSphere DataPower (an SOA Appliance) supports that - https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14107417 – Thiyagaraj Sep 19 '09 at 06:03