I have to generate schematron files for various xml schema files using the available information under the appinfo elements (i do xsl transformation to generate schemantron files, which are compiled again later).
The xpath rules required for schematron assertions are written under this appinfo element. However, these xpath rules do not contain any namespace prefix. Thus i can't use the schematron 'ns' tag to add a namespace to the compiled final xslt file.
The solution would be adding the xpath-default-namespace attribute to the final compiled xslt. Unfortunately i couldn't find any tag for adding xpath-default-namespace attribute.
Is there any workaround for this case? thanks.
There does not appear to be an option currently available to set a xpath-default-namespace
. In addition to transforming the generated XSLT, another option would be to modify/extend the schematron XSLT to generate the desired output so that you can get it generated in a single pass.
iso_schematron_skeleton_for_saxon.xsl
Override the template that generates the element to insert the
xpath-default-namespace` 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
to import your overriding stylesheet:Change the path to import your overriding 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"/>