Remove first line from a text file using XSLT

2019-07-19 01:38发布

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?

4条回答
霸刀☆藐视天下
2楼-- · 2019-07-19 02:14

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.

查看更多
Ridiculous、
3楼-- · 2019-07-19 02:28

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

查看更多
Bombasti
4楼-- · 2019-07-19 02:32

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>
查看更多
甜甜的少女心
5楼-- · 2019-07-19 02:36

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.

查看更多
登录 后发表回答