XSLT 可以解析文本字符串吗?
这是我第一次使用 XSLT。我正在尝试创建一个文件,将从我使用的程序导出的 XML 数据文件转换为 HTML 报告。
该元素的值之一是图像文件的路径,但生成的路径是绝对路径,例如
C:\Documents and Settings\me\Desktop\xml export\cd000402.jpg
但我想要一个仅到文件名的相对路径。
有没有办法通过 XLST 文件解析出文件名?
This is my first time using XSLT. I'm trying to create a file that will convert an XML data file exported from a program I use to an HTML report.
One of the element's value is path to an image file, but the path generated is an absolute path such as
C:\Documents and Settings\me\Desktop\xml export\cd000402.jpg
but I want a relative path to just the file name.
Is there some way through the XLST file to parse out the file name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
XPath 包含
substring-after
函数它返回另一个字符串第一次出现后的字符串。这本身还不够,但是像下面这样的模板可能会做到这一点:可用的字符串函数集并不是非常广泛,但我发现它对于 XSLT 中需要的大多数应用程序来说已经足够了。
XPath contains the
substring-after
function which returns the string following the first occurrence of another string. This isn't enough by itself, but a template such as the following might do it:The set of string functions available is not terribly extensive, but I've found that it is good enough for most applications that you'll need in XSLT.
这有点超出了问题的范围,但是 Michael Kay 有一个关于使用 XSLT 2 将纯文本解析为 XML 的优秀论文。
This is a little beyond the scope of the question, but Michael Kay has an excellent paper on using XSLT 2 to parse pure text into XML.
是的,请参阅 在 XSLT 2.0 中实现的通用 LR(1) 解析器。(仅 245 行)。
我已经用它实现了 JSON 解析器 和 XPath 2.0 解析器——完全采用 XSLT。
Yes, see a general LR(1) parser implemented in XSLT 2.0. (just in 245 lines).
I have implemented with it a parser for JSON and a parser for XPath 2.0 -- entirely in XSLT.
XSLT 借助 XPath 2.0 及其各种 字符串函数 帮助其处理这类事情。
示例:
假设所提到的 [to jpg file] 路径来自类似于
XSLT 片段的 xml 片段,则看起来像这样:
注意:没有时间测试;但这看起来是对的。
XSLT with the help of XPath 2.0 and its various string functions helps it deal with this type of things.
Example:
Assuming the path [to jpg file] mentioned in question comes from an xml snippet similar to
XSLT snippet would look something like
Note: didn't have time to test; but that looks about right.
这是可能的。我开发了以下脚本:
http://barsand.wordpress.com/2012/06/19/can-an-xslt-parse-a-string-of-text/" wordpress.com/2012/06/19/can-an-xslt-parse-a-string-of-text/
It is possible. I've developed the following script:
http://barsand.wordpress.com/2012/06/19/can-an-xslt-parse-a-string-of-text/