[英]XSLT; parse escaped text to a node-set and extract subelements
I've been fighting with this problem all day and am just about at my wit's end. 我整天都在与这个问题作斗争,并且快要结束了。
I have an XML file in which certain portions of data are stored as escaped text but are themselves well-formed XML. 我有一个XML文件,其中某些数据部分作为转义文本存储,但它们本身是格式正确的XML。 I want to convert the whole hierarchy in this text node to a node-set and extract the data therein.
我想将这个文本节点中的整个层次结构转换为一个节点集,并在其中提取数据。 No combination of variables and functions I can think of works.
我不能想到变量和函数的组合。
The way I'd expect it to work would be: 我希望它起作用的方式是:
<xsl:variable name="a" select="InnerXML">
<xsl:for-each select="exsl:node-set($a)/*">
'do something
</xsl:for-each>
The input element InnerXML contains text of the form 输入元素InnerXML包含以下格式的文本
<root><elementa>text</elementa><elementb><elementc/><elementd>text</elementd></elementb></root>
but that doesn't really matter. 但这并不重要。 I just want to navigate the xml like a normal node-set.
我只想像普通节点集一样浏览xml。
Where am I going wrong? 我要去哪里错了?
如果您可以使用Saxon 9.x ,它会提供saxon:parse()扩展函数来解决此任务。
what I've done is had a msxsl script in the xslt ( this is in a windows .NET environment): 我所做的是在xslt中有一个msxsl脚本(这是在Windows .NET环境中):
<msxsl:script implements-prefix="cs" language="C#" >
<![CDATA[
public XPathNodeIterator parse(String strXML)
{
System.IO.StringReader rdr = new System.IO.StringReader(strXML);
XPathDocument doc = new XPathDocument(rdr);
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr;
expr = nav.Compile("/");
XPathNodeIterator iterator = nav.Select(expr);
return iterator;
}
]]>
</msxsl:script>
then you can call it like this: 那么您可以这样称呼它:
<xsl:variable name="itemHtml" select="cs:parse(EscapedNode)" />
and that variable now contains xml you can iterate through 现在该变量包含xml,您可以迭代通过
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.