Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 之间的差异<;xsl:apply-template>;及<;xsl:calltemplate>;?_Xml_Xslt - Fatal编程技术网

Xml 之间的差异<;xsl:apply-template>;及<;xsl:calltemplate>;?

Xml 之间的差异<;xsl:apply-template>;及<;xsl:calltemplate>;?,xml,xslt,Xml,Xslt,请您解释一下和之间的区别,以及我应该在什么时候使用? 谢谢你在一个非常基本的层面上,当你想让处理器自动处理节点时,你可以使用,当你想更好地控制处理时,你可以使用。因此,如果你有: <foo> <boo>World</boo> <bar>Hello</bar> </foo> 然后,您可以在处理时调用此模板,而不是自动处理foo的子节点: <xsl:template match="foo">

请您解释一下
之间的区别,以及我应该在什么时候使用


谢谢你

在一个非常基本的层面上,当你想让处理器自动处理节点时,你可以使用
,当你想更好地控制处理时,你可以使用
。因此,如果你有:

<foo>
    <boo>World</boo>
    <bar>Hello</bar>
</foo>
然后,您可以在处理
时调用此模板,而不是自动处理
foo
的子节点:

<xsl:template match="foo">
    <xsl:call-template name="print-hello-world"/>
</xsl:template>

在这个特定的人工示例中,您现在得到了“Hello World”,因为您已经覆盖了默认处理来完成自己的事情

希望有帮助

你能给我解释一下两者的区别吗
以及何时使用

一个人可以使用
,但几乎不应该使用

XSLT的精神是允许XSLT处理程序准确地确定哪个模板与节点最匹配,并决定使用此模板处理该节点。这为我们提供了干净、简单和强大的可扩展性和多态性

通常,比较
xsl:apply templates
xsl:call template
类似于比较从基类调用虚拟方法与直接调用非虚拟方法的调用

以下是一些重要的区别:

  • xsl:apply-templates
    xsl:call-templates
    更丰富、更深入,甚至从
    xsl:for-each
    可以看出,这仅仅是因为我们不知道在 选择——在一般情况下,此代码对于 节点列表的不同节点

  • 将应用的代码 可以在编写
    xsl:apply-templates
    之后,通过 不认识原作者的人

  • 如果XSLT没有
    指令,在XSLT中实现高阶函数(HOF)是不可能的

    摘要:模板和
    指令是XSLT如何实现和处理多态性的。可以而且应该避免使用
    xsl:call-template
    ,因为它不允许多态,并且限制了可重用性和灵活性


    参考:查看整个主题:

    到目前为止,这是我读过的关于xslt的最好解释。(尽管我必须补充一点,xslt不是我的专长,可能永远也不会是)
    <xsl:template name="print-hello-world">
        <xsl:value-of select="concat( bar, ' ' , boo )" />
    </xsl:template>
    
    <xsl:template match="foo">
        <xsl:call-template name="print-hello-world"/>
    </xsl:template>