身份模板混乱 [英] Identity Template confusion

查看:26
本文介绍了身份模板混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解身份模板的功能.

I am trying to understand functinality of identity template.

  <xsl:template match='@* | node()'>
  <xsl:apply-templates select='@* | node()'/>
  </xsl:template>

上面的模板如果出现在我们的 XSL 文档的开头,我们称之为身份模板,它的功能是调用所有模板,即通过匹配 @* 和 node() 下的所有内容来匹配.然后它转到第二行 apply-templates,在那里它递归地选择所有模板/节点.如果我在这里错了,请纠正我.

The above template if present in start of our XSL document, we call it identity template and its function is to call all the templates i.,e., by matching every thing under @* and node() in match. Then it goes to second line apply- templates where it recursively selects all the templates/nodes. please correct me if i am wrong here.

我的问题是我们是否将这个模板放在 XSLT 的中间,而不是在开始时,我们不想要所有匹配的动作,而只想要存储在像

My question is if we have this template placed in middle of XSLT,but not in starting, and we dont want all the matching action, but only of a certain message stored in a variable like

  <xsl:template match='$variable holding entire soap envelope'>
  <xsl:apply-templates select='@* | node()'/>
  </xsl:template>

我们是否仍将其称为身份模板,并且在第一个操作中仍会像身份模板一样处理?

Do we still call it identity template and will still it processes same like identity template in first action.?

对不起,如果我的问题不清楚.

Sorry if my question is not clear.

感谢您的帮助.

推荐答案

不,覆盖身份转换的模板本身不会被视为身份转换.

No, templates overriding to the identity transformation would not themselves be considered to be identity transformations.

使用身份转换模板的方法是让它默认将所有内容从输入 XML 复制到输出 XML,但使用更具体的 match覆盖身份转换> 需要的模式.

The way to use the identity transformation template is to let it copy everything from the input XML to the output XML by default but to override the identity transformation with more specific match patterns where desired.

例如,考虑这个 SOAP 消息:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
  <env:Header>
    <n:alertcontrol xmlns:n="http://example.org/alertcontrol">
      <n:priority>1</n:priority>
      <n:expires>2001-06-22T14:00:00-05:00</n:expires>
    </n:alertcontrol>
  </env:Header>
  <env:Body>
    <m:alert xmlns:m="http://example.org/alert">
      <m:msg>Pick up Mary at school at 2pm</m:msg>
    </m:alert>
  </env:Body>
</env:Envelope>

如果我们想将此消息转换为另一个几乎相同的消息,但可能具有不同的 m:msg 内容,我们可以使用带有 >覆盖m:msg:

If we wanted to transform this message to another that's nearly the same, but perhaps with different m:msg content, we could use an identity transformation with an override for m:msg:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:m="http://example.org/alert">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="m:msg">
    <xsl:copy>***Pick up Mary at school at 1pm, not 2pm.***</xsl:copy>
  </xsl:template>

</xsl:stylesheet>

将上述 XSLT 应用于输入 SOAP 消息会生成相同的 SOAP 消息,但具有新的 m:msg 元素内容:

Applying the above XSLT to the input SOAP message produces an identical SOAP message but with new m:msg element contents:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
   <env:Header>
      <n:alertcontrol xmlns:n="http://example.org/alertcontrol">
         <n:priority>1</n:priority>
         <n:expires>2001-06-22T14:00:00-05:00</n:expires>
      </n:alertcontrol>
   </env:Header>
   <env:Body>
      <m:alert xmlns:m="http://example.org/alert">
         <m:msg>***Pick up Mary at school at 1pm, not 2pm.***</m:msg>
      </m:alert>
   </env:Body>
</env:Envelope>

这篇关于身份模板混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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