小智 4
这只是您可以执行的操作的一个小示例:
文件1.xml:
<foo>
<bar>Text from file1</bar>
</foo>
Run Code Online (Sandbox Code Playgroud)
文件2.xml:
<foo>
<bar>Text from file2</bar>
</foo>
Run Code Online (Sandbox Code Playgroud)
索引.xml:
<index>
<filename>file1.xml</filename>
<filename>file2.xml</filename>
Run Code Online (Sandbox Code Playgroud)
总结.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:variable name="big-doc-rtf">
<xsl:for-each select="/index/filename">
<xsl:copy-of select="document(.)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="big-doc" select="exsl:node-set($big-doc-rtf)"/>
<xsl:template match="/">
<xsl:element name="summary">
<xsl:apply-templates select="$big-doc/foo"/>
</xsl:element>
</xsl:template>
<xsl:template match="foo">
<xsl:element name="text">
<xsl:value-of select="bar"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
将样式表应用到index.xml将为您提供:
<?xml version="1.0" encoding="UTF-8"?><summary><text>Text from file1</text><text>Text from file2</text></summary>
Run Code Online (Sandbox Code Playgroud)
诀窍是使用文档函数(几乎所有 XSLT 1.0 处理器都支持的扩展函数)加载不同的文档,将内容作为变量体的一部分输出,然后将变量转换为节点集以进行进一步处理。
| 归档时间: |
|
| 查看次数: |
5022 次 |
| 最近记录: |