我正在尝试设置一个 XML 文档的样式,该文档使用 xinclude 来包含其他 xml 文件以实现模块化。我使用 Firefox 作为可视化转换的工具。(所有文件都在同一个文件夹中)目前我已经编写了以下 xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xi="http://www.w3.org/2001/XInclude"
exclude-result-prefixes='xsl xi'>
<xsl:template match="/interfaces">
<html>
<head>
<meta charset="UTF-8" content="text/html" http-equiv="Content-Type"/>
<title>Messages</title>
</head>
<body>
<xsl:apply-templates select="message"/>
</body>
</html>
</xsl:template>
<xsl:template match="message">
<xsl:value-of select="@name"/><br/>
<xsl:apply-templates select="xi:include[@href][@parse='xml' or not(@parse)]" />
</xsl:template>
<xsl:template match="xi:include">
Should be outputed...<xsl:apply-templates select="document(@href)" />
</xsl:template>
</xsl:stylesheet
要处理以下 xml:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='messages-xsl.xml'?>
<interfaces>
<message name="some_message">
<xi:include href="some_message.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
</message>
</interfaces>
我知道 stackoverflow 上的一些帖子提出了类似的问题,但到目前为止我无法解决这个问题。提前致谢。