加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – 与?之间的区别?

发布时间:2020-12-16 07:44:24 所属栏目:百科 来源:网络整理
导读:你能解释一下 xsl:apply-template之间的区别吗?和 xsl:call-template什么时候我应该使用 xsl:call-template ? 谢谢 在最基本的层面上,您使用 xsl:apply-templates当你想让处理器自动处理节点时,你使用 xsl:call-template /当你想要更好地控制处理时.
你能解释一下< xsl:apply-template>之间的区别吗?和< xsl:call-template>什么时候我应该使用< xsl:call-template> ?
谢谢
在最基本的层面上,您使用< xsl:apply-templates>当你想让处理器自动处理节点时,你使用< xsl:call-template />当你想要更好地控制处理时.所以如果你有:
<foo>
    <boo>World</boo>
    <bar>Hello</bar>
</foo>

你有以下XSLT:

<xsl:template match="foo">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="bar">
    <xsl:value-of select="."/>
</xsl:template>

<xsl:template match="boo">
    <xsl:value-of select="."/>
</xsl:template>

你会得到结果WorldHello.从本质上讲,你已经说过“以这种方式处理bar和boo”,然后你就让XSLT处理器处理这些节点.在大多数情况下,这就是你应该在XSLT中做的事情.

但有时候,你想做一些比较漂亮的事情.在这种情况下,您可以创建一个与任何特定节点都不匹配的特殊模板.例如:

<xsl:template name="print-hello-world">
    <xsl:value-of select="concat( bar,' ',boo )" />
</xsl:template>

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

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

在这个特殊的人工示例中,您现在可以获得“Hello World”,因为您已经覆盖了默认处理以执行自己的操作.

希望有所帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读