如何使用 XSLT 1.0 读取纯文本内容 [英] How to read plain text content with XSLT 1.0

查看:28
本文介绍了如何使用 XSLT 1.0 读取纯文本内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

源文件包含

Hello World, this is a nice world

将 XSLT 应用到输入文件所需的输出:

The output desired applying the XSLT to the input file:

<Hello_World message="this is a nice world"/>

我知道我可以在 XSLT 2.0 中轻松使用 unparsed-text,但我需要使用 XSLT 1.0.

I know I can use unparsed-text in XSLT 2.0 easily, but I need do it with XSLT 1.0.

我浏览了一段时间,找不到有用的东西.

I browsed a while, and I can't find something useful.

可以吗?我需要使用 Xalan XSLT 处理器.

Is it posible? I need to use Xalan XSLT processor.

我认为这个问题很有挑战性.

I think this question is challenging.

推荐答案

输入文档不可能是纯文本,因为XSLT 1.0 转换的输入必须是格式良好的 XML.

It is not possible for the input document to be plain text because the input to an XSLT 1.0 transformation must be well-formed XML.

以下是一些在 XSLT 转换中访问纯文本的替代方法:

Here are some alternative ways to access plain text in an XSLT transformation:

  • 使用未解析文本XSLT 2.0 中的strong>.
  • 通过顶级参数 (xsl:param).
  • 预处理文本文件,将其转换为格式良好的 XML 文档.
  • 动态生成 XSLT 文件,可能通过元 XSLT 转换,并将纯文本直接包含在 XSLT 源中.然后只需使用一个虚拟的 XML 输入文件.
  • 在包装器 XML 中将文本文件引用为外部实体文档,然后使用 XSLT 处理包装器 XML 文档.
  • Use unparsed-text in XSLT 2.0.
  • Pass the plain text in via top-level parameters (xsl:param).
  • Preprocess the text file to turn it into a well-formed XML document.
  • Generate the XSLT file dynamically, possibly via a meta XSLT transformation, and include the plain text directly in the XSLT source. Then just use a dummy XML input file.
  • Reference the text file as an external entity in a wrapper XML document, and then process the wrapper XML document using XSLT.

以下是外部实体技术的示例:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wrapper [
<!ENTITY textFile SYSTEM "file.txt">
]>
<wrapper>&textFile;</wrapper>

(请注意,鉴于 XSLT 1.0 的字符串处理能力有限,最后一个选项可能具有挑战性,但对于某些数据,它可能是可行的.)

(Note that this last option could be challenging given XSLT 1.0's limited string processing abilities, but for some data, it may be viable.)

这篇关于如何使用 XSLT 1.0 读取纯文本内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆