开发者

XSLT getting a piece of xml to custommethod

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>


If you just want to get the tag name, try

<xsl:template match="SpecialNode">
    <xsl:value-of select="CustomMethod:Handler(name(.))"/>
</xsl:template>

If you want the whole element, as well as the tag name, try

<xsl:template match="SpecialNode">
    <xsl:value-of select="CustomMethod:Handler(., name(.))"/>
</xsl:template>


Use:

CustomMethod:Handler(.)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜