如果镜像输入数据,XSL 文档会是什么样子?
XSL 的典型用法是:
XML1.xml -> *transformed using xsl* -> XML2.xml
如果我想简单地镜像输入数据,XSL 文档是什么样子?
前任:
XML1.xml -> *transformed using xsl* -> XML1.xml
The typicle XSL usage is:
XML1.xml -> *transformed using xsl* -> XML2.xml
How does an XSL document look like, if I want to simply mirror the input data?
ex:
XML1.xml -> *transformed using xsl* -> XML1.xml
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个问题有多个答案,但所有这些答案都可以命名为“身份转换”:
这是最短、最简单、最高效、最不灵活、不可扩展且无用的身份转换。经典身份规则,每个人都知道(或应该知道):
_
这仍然是一个非常短的单模板转换,它是一种更具可扩展性和有用的身份转换,也称为“身份规则”。使用和覆盖身份转换是最基本、最强大的 XSLT 设计模式,只需几行即可解决常见的复制和替换/重命名/删除/添加问题。也许
xslt
标记中 90% 以上的答案都使用这种形式的恒等转换。.3. 细粒度控制身份规则,每个人都应该知道(而且很少有人知道):
这与上面 2. 中定义的众所周知的身份规则类似,但它提供了对XSLT 处理。
通常,2.
会触发许多转换(对于所有属性和子节点),可以在任何顺序甚至并行。在某些任务中,我们不希望在某些其他节点之后处理某些类型的节点,因此我们必须通过使用与不需要的节点匹配的空模板覆盖它并在特定模式下添加其他模板来调查身份规则的泄漏“当时间到来时”处理这些节点....3。更适合我们需要更多控制和真正顺序类型处理的任务。
有些任务用 2. 很难解决,但用 3. 就很容易解决。
There are more than one answers to this question, however all of them could be named "Identity Transform":
<xsl:copy-of select="/"/>
This is the shortest, simplest, most efficient and most inflexible, non-extensible and unuseful identity transform.The classical identity rule, which everybody knows (or should know):
_
This is still very short, one-template transformation, which is so much more extensible and useful identity transform, known also as the "identity rule". Using and overriding the identity transform is the most fundamental and powerful XSLT design pattern, allowing to solve common copy and replace/rename/delete/add problems in just a few lines. Maybe 90%+ of all answers in the
xslt
tag use this form of the identity transform..3. The fine-grained control identity rule, which everybody should know (and very few people know):
This is similar to the generally known identity rule defined at 2. above, but it provides a finer control over the XSLT processing.
Typically with 2. the
<xsl:apply-templates select="@*|node()">
triggers a number of transformations (for all attributes and child nodes), that can be done in any order or even in parallel. There are tasks where we don't want certain types of nodes to be processed after some other nodes, so we have to plumb the leakage of the identity rule with overriding it with empty templates matching the unwanted nodes and adding other templates in a specific mode to process these nodes "when the time comes"....3. is more appropriate for tasks where we want more control and really sequential-type processing.
Some tasks that are very difficult to solve with 2. are easy using 3.
它看起来像身份转换:
这是最基本的 XSLT 转换之一。它匹配任何属性或其他节点,复制其匹配的内容,然后将其自身应用于匹配节点的所有属性和子节点。
事实证明,这对于其他任务也非常强大。一个常见的要求是原样复制源文件的大部分内容,同时以特殊方式处理某些元素。这可以使用恒等变换加上特殊节点的模板来解决。这是一个通用、灵活(且简短)的解决方案。
It would look like the identity transform:
This is one of the most fundamental XSLT transforms. It matches any attribute or other node, copies what it matches, and then applies itself to all attributes and child nodes of the matched node.
This turns out to be quite powerful for other tasks, too. A common requirement is to copy most of a source file unchanged, while handling certain elements in a special way. This can be solved using the identity transform plus one template for the special nodes. It's a generic, flexible (and short) solution.
这会匹配每个元素或属性并递归地应用模板。
This matches every element or attribute and recursively applies the template.