我必须使用appinfo元素下的可用信息为各种xml模式文件生成schematron文件(我进行xsl转换以生成schemantron文件,稍后将再次编译)。
schematron断言所需的xpath规则是在这个appinfo元素下编写的。但是,这些xpath规则不包含任何命名空间前缀。因此,我不能使用schematron'ns'标记将命名空间添加到编译的最终xslt文件中。
解决方案是将xpath默认名称空间属性添加到最终编译的xslt中。不幸的是,我找不到任何用于添加xpath默认名称空间属性的标记。
这种情况有什么变通办法吗?谢谢
当前似乎没有可用于设置xpath-default-namespace
的选项。除了转换生成的XSLT之外,另一个选项是修改/扩展模式XSLT以生成所需的输出,这样您就可以在一次通过中生成它
- 创建一个导入
iso_schematron_skeleton_for_saxon.xsl
的样式表
覆盖生成element to insert the
xpath默认名称空间`attribute:的模板
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl"
version="2.0"
>
<xsl:import href="iso_schematron_skeleton_for_saxon.xsl"/>
<!-- Using XSLT 2 -->
<xsl:template
match="iso:schema[@queryBinding='xslt2' or @queryBinding ='xpath2']"
priority="10">
<axsl:stylesheet
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:saxon="http://saxon.sf.net/">
<!-- insert the default namespace attribute -->
<xsl:attribute name="xpath-default-namespace" select="'http://your/default/namespace/goes/here'"/>
<xsl:apply-templates
select="iso:ns" />
<!-- Handle the namespaces before the version attribute: reported to help SAXON -->
<xsl:attribute name="version">2.0</xsl:attribute>
<xsl:apply-templates select="." mode="stylesheetbody"/>
<!-- was xsl:call-template name="stylesheetbody"/ -->
</axsl:stylesheet>
</xsl:template>
</xsl:stylesheet>
- 修改
iso_svrl_for_xslt2.xsl
以导入覆盖样式表:
更改导入覆盖XSLT:的路径
<!-- Select the import statement and adjust the path as
necessary for your system.
-->
<xsl:import href="iso_schematron_skeleton_for_saxon_with_default_namespace.xsl"/>
由于XSLT是一个XML文件,您可以转换编译/转换的模式XSLT并自己插入@xpath-default-namespace
:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<xsl:copy>
<xsl:attribute name="xpath-default-namespace" select="'http://your/default/namespace'"/>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>