ive included files used produce error.
these work in oxygen; python lxml script does not work.
more specifically, transform works, validation errors not work properly. ( example if id
changed ids
.)
toy.xml
<?xml version="1.0" encoding="utf-8"?> <?xml-model href="file:/randng.rnc" type="application/relax-ng-compact-syntax"?> <?xml-model href="file:/toytest.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?> <report> <title>variant calling , annotation dr.smith</title> <date>july 1,1985</date> <analysis id="ngs"> <method id="qc"></method> <method id="gatk"></method> </analysis> <analysis id="genome_alignment"> <method id="bowtie2"></method> </analysis> </report>
test.xsl
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="/"> <html> <head> <h2>report dr zoidberg</h2> <div><xsl:value-of select="current-date()"/></div> <div><xsl:apply-templates select="/report/date"></xsl:apply-templates></div> </head> <body> <h2>table of contents</h2> <ul><xsl:apply-templates select="//analysis" mode="toc"/></ul> <h2>analysis</h2> <ul><xsl:apply-templates select="//analysis" mode="analysis"/></ul> <!-- <xsl:apply-templates select="/report/analysis/method"/>--> <h2>citations</h2> <ul><xsl:apply-templates select="//method" mode="cite"></xsl:apply-templates></ul> </body> </html> </xsl:template> <!-- list analysis --> <xsl:template match="analysis" mode="analysis"> <li id="{@id}"> <xsl:apply-templates select="@id"/> <ul><xsl:apply-templates select="/analysis/method"></xsl:apply-templates> <xsl:apply-templates select="method"/> </ul> </li> </xsl:template> <!-- list methods --> <xsl:template match="method"> <li> <xsl:apply-templates select="@id"/> <!--citation--> <xsl:for-each select="document('contentconfig.xml')/cfg/analysis/method[@id=current()/@id]/citation"> <sup> <a href="#cite{count(preceding::citation) + 1}"> <xsl:value-of select="count(preceding::citation) + 1"/> </a> </sup> </xsl:for-each> </li> </xsl:template> <!--toc based on analysis --> <xsl:template match="analysis" mode="toc"> <li> <a href="#{@id}"> <xsl:apply-templates select="@id"/> </a> </li> </xsl:template> <!--citations --> <xsl:template match="method" mode="cite"> <xsl:for-each select="document('contentconfig.xml')/cfg/analysis/method[@id=current()/@id]/citation"> <li> <cite id="cite{count(preceding::citation) + 1}"> [<xsl:value-of select="count(preceding::citation) + 1"/>] <xsl:apply-templates/> </cite> </li> </xsl:for-each> </xsl:template> </xsl:stylesheet>
randng.rng
<!--<?xml version="1.0" encoding="utf-8"?>--> <grammar xmlns="http://relaxng.org/ns/structure/1.0"> <start> <ref name="report"/> </start> <define name="report"> <element name="report"> <optional> <ref name="title"/> </optional> <optional> <ref name="date"/> </optional> <oneormore> <ref name="analysis"/> </oneormore> </element> </define> <define name="title"> <element name="title"> <text/> </element> </define> <define name="date"> <element name="date"> <text/> </element> </define> <define name="analysis"> <element name="analysis"> <attribute name="id"/> <oneormore> <ref name="method"/> </oneormore> </element> </define> <define name="method"> <element name="method"> <attribute name="id"/> <text/> </element> </define> </grammar>
toytest.sch
<schema xmlns="http://purl.oclc.org/dsdl/schematron" > <pattern id="sum_equals_100_percent"> <title>sum equals 100%.</title> <rule context="total"> <assert test="sum(//percent)=100">sum not 100%.</assert> </rule> </pattern> </schema>
however, when try use python lxml relaxng_err_elemname
. here python script:
import shlex, subprocess lxml import isoschematron lxml import etree # _validate_ # parse sch,xml,relaxng parser_xml = etree.xmlparser() sch_doc = etree.parse('toy.sch') schematron = isoschematron.schematron(sch_doc, store_report = true) #xml_doc = etree.parse('toy.xsl', parser_xml) xml_doc = etree.parse('toy.xsl') ##compact relaxng #pytrang randng.rnc randng.rng randng_doc = etree.parse('randng.rng') relaxng = etree.relaxng(randng_doc) # validate against schematron validationresult = schematron.validate(xml_doc) print '--------------------' print validationresult # validate against relaxng try: validaterelaxng = relaxng.assert_(xml_doc) print 'relaxng worked' except assertionerror e: error = relaxng.error_log.last_error print relaxng.error_log print error.type_name if error.type_name == 'relaxng_err_attrvalid': print 'invalid attribute' # relaxng_err_elemname # _transform_ #just run shell cmd = "java -cp /usr/share /java/saxonb.jar net.sf.saxon.transform -xsl:test2.xsl -s:toy.xml -o:toy6.html" args = shlex.split(cmd) #subprocess.popen(args)
the transformation works, validation not produce proper errors.
i ended using command line call transform. sch , rng files xslt_1.0 compliant? other problems why cannot simple script work?
best
accidentally trying parse stylesheet... should have figured out element error. instead should parse xml doc, , validate against that.