XSLT 将一段 xml 获取到自定义方法
我有一个关于 XSLT 的小问题,我最近才开始使用 xslt。 所以问题是我需要用我的自定义方法提供一段与模板匹配的 xml,但问题是,我提供的是一个字符串,但它不再有标签了: 例如,如果我的 xml 如下所示:
<a>hi</a>
<a>bye</b>
我只收到包含以下内容的字符串:“hi bye” 所以我需要给出的不仅仅是节点的值/文本,而是带有标签、属性和元素等的整个节点。 我的 xslt 看起来像这样:
<xsl:template match="SpecialNode">
<xsl:value-of select="CustomMethod:Handler(node()[*], @name)"/>
</xsl:template>
但无论我尝试什么(例如 ./node()
或 descendant::node()
或 *
等等),我总是得到没有 xml 标签的字符串:( 但我需要将类似的内容以字符串形式传递给我的方法。
<a>hi</a><a>bye</a>
I have a small question about XSLT, I've only recently started with xslt.
So the thing is I need to give with my custom method a piece of xml that matches the template, but the problem is, what I give is a string but it doenst have tags anymore:
so example if my xml looks like this:
<a>hi</a>
<a>bye</b>
I recieve only string that consists as this: "hi bye"
So I need to give instead of only the value/text of the node, but whole node with tags and attributes and elements etc etc.
My xslt looks like this:
<xsl:template match="SpecialNode">
<xsl:value-of select="CustomMethod:Handler(node()[*], @name)"/>
</xsl:template>
but whatsoever I tried (like ./node()
or descendant::node()
or *
and so on), I always get the string without xml tags :(
but I need to have something like this passed to my method in a string.
<a>hi</a><a>bye</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只想获取标签名称,请尝试
如果您想要整个元素以及标签名称,请尝试
If you just want to get the tag name, try
If you want the whole element, as well as the tag name, try
使用:
Use:
您的 XSLT 样式表正在处理节点树,并且您希望外部 C# (?) 代码查看包含尖括号的词法序列化 XML。因此,节点树需要在某个地方序列化为词法 XML。这不会像函数调用完成的隐式转换那样神奇地发生。最好让 C# 代码将数据作为节点接收,并从那里进行序列化 - 假设处理不能是树级别的节点。
Your XSLT stylesheet is processing a tree of nodes, and you want your external c# (?) code to see lexical serialized XML containing angle brackets. So the tree of nodes needs to be serialized into lexical XML somewhere along the line. That's not going to happen by magic as an implicit conversion done by a function call. It's probably best to let the C# code receive the data as nodes, and do the serialization from there - assuming the processing can't be node at the tree level.