XSLT:读取作为字符串传递的 xml 文档的参数 [英] XSLT: Reading a param that's an xml document passed as a string

查看:37
本文介绍了XSLT:读取作为字符串传递的 xml 文档的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了另一位工程师的问题.作为一名新工程师,我必须想办法解决这个问题,但我一直没能做到.任何帮助将不胜感激,我发现最接近的是 Chunk string with XSLT 但是还没有完全到位.我只能使用 XSL v1.0.

I have ran into an issue with another engineer. Being a new engineer, I have to figure out the solution to this, but I haven't been able to. Any help would be appreciated, the closest thing I've found is Chunk string with XSLT but is still not quite there. I'm only able to use XSL v1.0.

一个参数作为一个巨大的字符串传递给我的样式表.它最初来自一个 XML 文档.字符串看起来像这样.

A parameter is passed to my stylesheet as a giant string. It originally came from an XML Document. The string looks something like this.

使用 <xsl:value-of select="$servers"/> 其中 $servers 是传递给我的字符串的参数.字符串如下所示:

With <xsl:value-of select="$servers"/> where $servers is the param for the string passed to me. The string looks like this:

MIKE180<;/expiration><left>0</left><comment></comment></server><server><name>Susie</name><capacity>0</capacity>;status>1</status><expiration>2014-07-04T00:00:00Z</expiration><left>5238568</left><comment></comment><server><name>Zoe</name><capacity>5000</capacity><status>1</status><expiration></expiration><left>0</left><comment;</comment></server></active_servers></license>

这是作为参数传递给样式表的一段 xml 数据.实际文档是 300 行左右的数据.将这些节点"分开的唯一区别是 .如果它是一个非常大的字符串,有没有办法从中提取数据?

This is a section of the xml data passed as a param to the stylesheet. The actual document is 300 or so lines of data. The only distinctive thing that separates these "nodes" are the <server> and </server>. Is there a way to pull data out of this if it's a really big string?

比如说.我需要找到佐伊",看看她是否有到期",如果没有,我需要她的状态".所以 Zoe 将显示1"作为状态,因为她没有过期.而 MIKE 将显示0",而 Susie 将显示 2014-07-04T00:00:00Z.

Say, for example. I need to find "Zoe" and see if she has a "expiration", if she doesn't, I need her "status". So Zoe will display "1" for status since she doesn't have expiration. While MIKE will display "0" and Susie will display 2014-07-04T00:00:00Z.

为了找到解析/读取巨大字符串的解决方案,我已经遍及谷歌和堆栈溢出.但我还没有找到足够接近的解决方案,我可以让它发挥作用.到目前为止,我一直没有工作副本,并且在研究 2 天后却一无所获.

I have looked all over google and stack overflow for finding a solution to parsing/reading a giant string. But I haven't come to a solution close enough where I can make it work. As of right now, I'm stuck having no working copy, and 2 days into research without getting anywhere.

推荐答案

一个字符串不是 XML,不能被解析为作为 XML.您当然可以使用 XSLT 1.0 提供的字符串函数将字符串 解析为字符串 - 这会非常乏味且容易出错.

A string is not XML and cannot be parsed as XML. You could of course parse the string as string, using the string functions provided by XSLT 1.0 - which would be quite tedious and error-prone.

如果可能,将路径作为参数传递给实际的 XML 文档.或者,串联调用两个转换,第一个转换将参数保存到具有已知路径的文件中,第二个转换从该文件中读取.

If possible, pass a path to an actual XML document as the parameter. Alternatively, call two transformations in series, with the first transformation saving the parameter to a file with a known path, and the second transformation reading from that file.

另见:
https://stackoverflow.com/a/14512924/3016153

这篇关于XSLT:读取作为字符串传递的 xml 文档的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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