将字符串转换为 xsl 中的节点列表 [英] Converting a string as a nodelist in xsl

查看:24
本文介绍了将字符串转换为 xsl 中的节点列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个字符串 (XSLT 1.0),我想将其转换为 NodeList,以便可以在以下示例中使用.

I currently have a string (XSLT 1.0) which I'd like to turn into a NodeList so that it can be used the following example.

($testString 代表 XML 树中的一个元素)

($testString represents an element in a XML tree)

<xsl:apply-templates select="$testString">

<xsl:template match="$testString">

我尝试使用以下方法,但似乎都不起作用

I have tried using the following but neither seem to work

<xsl:apply-templates select="xx:node-set($testString)">
<xsl:apply-templates select="exslt:node-set($testString)">

是否可以将字符串转换为另一个具有 NodeList 属性的变量?或者这有什么办法吗?

Is there a away to convert the string to another variable which ahs NodeList properties? Or is there anyway around this?

更新:我目前有一个使用 XML 调用 XSL 的 JSP.JSP 页面接受传递给 XSL 页面的字符串.该字符串表示 XML 中的一个元素.我正在尝试搜索每个节点以查找该元素并返回该元素的值.

Update: I currently have a JSP which calls an XSL using XML. The JSP page takes in a string which is passed to the XSL page. The string represents an element in the XML. I am trying to search through each Node looking for that element and return the value of the element.

推荐答案

您的样式表中是否有 exslt 命名空间声明?以下适用于任何 xml 输入(libxslt/xsltproc)

Have you got the exslt namespace declaration in your stylesheet? The following works for me with any xml input (libxslt / xsltproc)

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:exslt="http://exslt.org/common"
    version="1.0">

    <xsl:template match="/">
        <xsl:variable name="xml-string"><foo bar="baz">etc...</foo></xsl:variable>
        <xsl:variable name="xml-node" select="exslt:node-set($xml-string)"/>
        Bar is <xsl:value-of select="$xml-node//@bar"/>
    </xsl:template>

</xsl:stylesheet>

这篇关于将字符串转换为 xsl 中的节点列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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