如何解决XSL转换以输出许多嵌入式XSL样式表
我希望编写一个XSL转换,该输出在TEMPLATE元素内输出许多嵌入式样式表(样式表集合由另一个组件提取并应用所需的下游组件处理)。因此,作为转换的结果,我要生成的是一个包含如下内容的XML文件:
<?xml version="1.0"?>
<TEMPLATEDATA xmlns="http://www.sanjay.com/appname" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<TEMPLATE name="addFocus" operation="Add">
<xsl:stylesheet version="1.0">
<xsl:template match="/">
<STRATEGICFOCUS />
</xsl:template>
</xsl:stylesheet>
</TEMPLATE>
<TEMPLATE name="addOrg" operation="Init">
<xsl:stylesheet version="1.0" xmlns:app="http://www.sanjay.com/myapp">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="Name"></xsl:param>
<xsl:template match="*">
<CONTENT>
<NAME><xsl:value-of select="$Name"/></NAME>
</CONTENT>
</xsl:template>
</xsl:stylesheet>
</TEMPLATE>
</TEMPLATEDATA>
我想通过定义这样的XSL转换来产生此输出(忽略不重要的我正在转换的输入XML):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.sanjay.com/myapp">
<xsl:template match="/">
<TEMPLATEDATA>
<xsl:call-template name="template1" />
<xsl:call-template name="template2" />
</TEMPLATEDATA>
</xsl:template>
<xsl:template name="template1">
<TEMPLATE name="addFocus" operation="Add">
<xsl:stylesheet version="1.0">
<xsl:template match="/">
<STRATEGICFOCUS />
</xsl:template>
</xsl:stylesheet>
</TEMPLATE>
</xsl:template>
<xsl:template name="template2">
<TEMPLATE name="addOrg" operation="Init"
<xsl:stylesheet version="1.0" xmlns:app="http://www.sanjay.com/myapp">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="Name"></xsl:param>
<xsl:template match="*">
<CONTENT>
<NAME>
<xsl:value-of select="$Name"/>
</NAME>
</CONTENT>
</xsl:template>
</xsl:stylesheet>
</TEMPLATE>
</xsl:template>
</xsl:stylesheet>
我收到样式表的XSL解析错误,说内部xsl:stylesheet无效,因为它不能是TEMPLATE元素的子元素。谁能告诉我该如何解决?我知道我可以在CDATA部分中嵌入内部样式表,但我不想这样做。
sanjay
解决方法
您似乎想对结果元素使用名称空间别名https://www.w3.org/TR/xslt-30/#element-namespace-alias,例如
<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
声明了xmlns:axsl="http://www.w3.org/1999/XSL/Transform-alias"
并用于例如
<xsl:template name="template1">
<TEMPLATE name="addFocus" operation="Add">
<axsl:stylesheet version="1.0">
<axsl:template match="/">
<STRATEGICFOCUS />
</axsl:template>
</xasl:stylesheet>
</TEMPLATE>
</xsl:template>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。