自动化 exslt:node-set? [英] Automating exslt:node-set?

查看:25
本文介绍了自动化 exslt:node-set?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定这是否可行,但尝试设置一些不会使我在从动态创建的节点块中提取值时必须键入 exslt:node-set 的内容.我将整个节点集存储在一个变量中,并将其包装在 exslt:node-set 中,但是为什么当我尝试从中提取时它不起作用.这可能吗?

Not sure if this is possible, but trying set up something that doesn't make me have to type exslt:node-set when pulling values from a dynamically created node block. I am storing the entire set of nodes in a variable, and wrapping it in exslt:node-set, but why does it not work when I then try to pull from it. Is this possible?

<xsl:variable name="LANG">
    <xsl:variable name="tmp">
        <xsl:element name="foo">
            <xsl:element name="bar">Hello</xsl:element>
        </xsl:element>
    </xsl:variable>
    <xsl:value-of select="exslt:node-set($tmp)"/>
</xsl:variable>


<!-- Love to be able to do this --> 
<xsl:value-of select="$LANG/foo/bar"/>

<!-- This does work --> 
<xsl:value-of select="exslt:node-set($LANG)/foo/bar"/>

推荐答案

在 XSLT 1.0 中,在您的示例中定义的变量称为结果树片段 (RTF),您只能使用 xsl:copy-of整个片段复制到结果树或 xsl:value-of 复制整个内容.示例

In XSLT 1.0, the variable defined as in your example are called result tree fragments (RTF) and you can only use xsl:copy-of to copy the entire fragment to the result tree or xsl:value-of to copy the entire content. Example

 <xsl:copy-of select="$LANG"/>

如果要将变量视为临时树,则需要 node-set() 扩展.

If you want treat the variable as a temporary tree you need the node-set() extension.

在 XSLT 1.0 中处理静态树片段(如查找表)的常用方法是将它们定义为样式表根元素的子元素(使用自定义名称空间).然后您可以使用 document() 函数来检索所需的值.

The common way to deal with static tree fragments (like lookup tables) in XSLT 1.0 is to define them as children of the stylesheet root elements (using a custom namespace). Then you can use the document() function to retrieve the wanted value.

注意如果您使用的是 Saxon (v>6.5),您只需将样式表版本设置为 1.1,您就可以在没有任何节点的情况下管理 RTF-设置扩展名.

Note If you are using Saxon (v>6.5), you could simply set the stylesheet version to 1.1 and you will be able to manage the RTF without any node-set extension.

[XSLT 1.0]

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:empo="http://stackoverflow.com/users/253811/empo">

    <empo:LANG>
        <empo:foo>
            <empo:bar>Hello</empo:bar>
        </empo:foo>
    </empo:LANG>

    <xsl:template match="/">
        <xsl:variable name="LANG" select="document('')/*/empo:LANG"/>
        <xsl:value-of select="$LANG/empo:foo/empo:bar"/>
    </xsl:template>

</xsl:stylesheet>

这篇关于自动化 exslt:node-set?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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