transform using XSLT with method="text" has empty result

I have a style sheet that outputs validation messages as JSON, i.e. output method=„text“. Using xsltproc from libxml2 yields a correct result: xsltproc rules/schtron_xsl/rule00I.xsl testdata/idp_valid.xml "00": { "Severity": "Info", "Message": "Validating entityID https://idp5.test.example.org/idp.xml", "Context“, "/md:EntitiesDescriptor[1]/md:EntityDescriptor[1]", "Rule": "@entityID" } Whereas I get an empty result with lxml: [https://github.com/identinetics/saml_schematron/blob/dev/scripts/try_xslt2te...] import lxml.etree as etree with open('rules/schtron_xsl/rule00I.xsl') as fd: transform = etree.XSLT(etree.XML(''.join(fd.readlines()))) with open('testdata/idp_valid.xml') as fd: md_dom = etree.parse(fd) result_xml = (transform(md_dom)) print(etree.tostring(result_xml)) (Data files relative to https://github.com/identinetics/saml_schematron/blob/dev/) What is the correct method to get non-XML result objects from xslt? Best regards Rainer Hörbe

Hi,
I *think* the problem might be that etree.tostring() is only meaningful on XML (result) trees whereas your transformation result isn't XML. (so it probably shouldn't be named result_xml, either ;-)) Try str(result_xml) # or bytes(result_xml) What does that give you? Note: rules/schtron_xsl/rule00I.xsl doesn't seem to be in the github repo (probably some generated file, as you're dealing with schematron here?) Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart

Right, the object type is XSLTResultTree.
Tt is empty in both cases. I made a screenshot of the variables at the last statement: https://github.com/identinetics/saml_schematron/blob/dev/scripts/try_xslt2te...
Note: rules/schtron_xsl/rule00I.xsl doesn't seem to be in the github repo (probably some generated file, as you're dealing with schematron here?)
Yes, that is in .gitignore. I added it. Thanks, Raiber

Hi,
Seems you get an error in the transform error log (see also your screenshot): $ python2.7 -c 'from lxml import etree, html; transform = etree.XSLT (etree.parse("rules/schtron_xsl/rule00I.xsl")); xmltree = etree.parse ("testdata/idp_valid.xml"); result = transform(xmltree); print str(result); print transform.error_log' <string>:0:0:ERROR:XSLT:ERR_OK: unknown error As to why xsltproc handles this differently (sees no error/ignores this error/...), I have no idea. I realize you had problems with differences between xsltproc and lxml behaviour before (https://bugs.launchpad.net/lxml/+bug/1567633) Maybe these have the same root cause? You'll probably have to dig into lxml's xslt code... Funny thing is: Again, if I run the xslt through oxygen and repeat I see a different error_log: Now the report result texts show up in there... $ python2.7 -c 'from lxml import etree, html; transform = etree.XSLT (etree.parse("oxygened_rule00I.xsl")); xmltree = etree.parse ("testdata/idp_valid.xml"); result = transform(xmltree); print str(result); print transform.error_log' <string>:0:0:ERROR:XSLT:ERR_OK: "00": { "Severity": "Info", "Message": "Validating entityID https://idp5.test.example.org/idp.xml", "Context", "/md:EntitiesDescriptor[1]/md:EntityDescriptor[1]", "Rule": "@entityID" } Btw. I run a rather old stack - so no idea if using the latest & greatest libxml2, libxslt + lxml might make this problem disappear. Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart

In fact it is. My error, I forgot about the previous discussion. Back then I switched to lxml.isoschematron as you recommended then. However, plain schematron does not point you to the xpath of the element triggering the schematron rule. That is why I went back to xslt, generating it from schematron with an additional xslt: https://github.com/identinetics/saml_schematron/blob/dev/lib/message.xsl
You'll probably have to dig into lxml's xslt code…
I did not look in lxml, but in the xslt, where I identified the cause: If the text node start with a newline lxml returns an „unknown error“. I created an issue on github.
lxml 3.6.4 and python 3.4.5 Thank you Rainer

Hi,
Where does this xpath (of the element triggering) show up? In the schematron result svrl-report? If so you should be able to access it there if you use isoschematron.Schematron(..., store_report=True): I.e. is it <svrl:fired-rule context="md:EntityDescriptor"/><svrl:successful-report test="@entityID" ... you're looking for, or s.th. else? Note that you can also customize the actual xsl transformations used by lxml.isoschematron, if you'd like to deviate from the default skeleton implementation. Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart

Rainer Hoerbe schrieb am 23.09.2016 um 09:40:
I created an issue on github.
Please note that lxml doesn't use issue tracking on github. The bug tracker is here: https://bugs.launchpad.net/lxml This should fix your problem, though: https://github.com/lxml/lxml/commit/fd4a5c5d23fbb7e7575f82bd6f1b027bd5c17038 Thanks for the report. Stefan

Hi,
I *think* the problem might be that etree.tostring() is only meaningful on XML (result) trees whereas your transformation result isn't XML. (so it probably shouldn't be named result_xml, either ;-)) Try str(result_xml) # or bytes(result_xml) What does that give you? Note: rules/schtron_xsl/rule00I.xsl doesn't seem to be in the github repo (probably some generated file, as you're dealing with schematron here?) Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart

Right, the object type is XSLTResultTree.
Tt is empty in both cases. I made a screenshot of the variables at the last statement: https://github.com/identinetics/saml_schematron/blob/dev/scripts/try_xslt2te...
Note: rules/schtron_xsl/rule00I.xsl doesn't seem to be in the github repo (probably some generated file, as you're dealing with schematron here?)
Yes, that is in .gitignore. I added it. Thanks, Raiber

Hi,
Seems you get an error in the transform error log (see also your screenshot): $ python2.7 -c 'from lxml import etree, html; transform = etree.XSLT (etree.parse("rules/schtron_xsl/rule00I.xsl")); xmltree = etree.parse ("testdata/idp_valid.xml"); result = transform(xmltree); print str(result); print transform.error_log' <string>:0:0:ERROR:XSLT:ERR_OK: unknown error As to why xsltproc handles this differently (sees no error/ignores this error/...), I have no idea. I realize you had problems with differences between xsltproc and lxml behaviour before (https://bugs.launchpad.net/lxml/+bug/1567633) Maybe these have the same root cause? You'll probably have to dig into lxml's xslt code... Funny thing is: Again, if I run the xslt through oxygen and repeat I see a different error_log: Now the report result texts show up in there... $ python2.7 -c 'from lxml import etree, html; transform = etree.XSLT (etree.parse("oxygened_rule00I.xsl")); xmltree = etree.parse ("testdata/idp_valid.xml"); result = transform(xmltree); print str(result); print transform.error_log' <string>:0:0:ERROR:XSLT:ERR_OK: "00": { "Severity": "Info", "Message": "Validating entityID https://idp5.test.example.org/idp.xml", "Context", "/md:EntitiesDescriptor[1]/md:EntityDescriptor[1]", "Rule": "@entityID" } Btw. I run a rather old stack - so no idea if using the latest & greatest libxml2, libxslt + lxml might make this problem disappear. Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart

In fact it is. My error, I forgot about the previous discussion. Back then I switched to lxml.isoschematron as you recommended then. However, plain schematron does not point you to the xpath of the element triggering the schematron rule. That is why I went back to xslt, generating it from schematron with an additional xslt: https://github.com/identinetics/saml_schematron/blob/dev/lib/message.xsl
You'll probably have to dig into lxml's xslt code…
I did not look in lxml, but in the xslt, where I identified the cause: If the text node start with a newline lxml returns an „unknown error“. I created an issue on github.
lxml 3.6.4 and python 3.4.5 Thank you Rainer

Hi,
Where does this xpath (of the element triggering) show up? In the schematron result svrl-report? If so you should be able to access it there if you use isoschematron.Schematron(..., store_report=True): I.e. is it <svrl:fired-rule context="md:EntityDescriptor"/><svrl:successful-report test="@entityID" ... you're looking for, or s.th. else? Note that you can also customize the actual xsl transformations used by lxml.isoschematron, if you'd like to deviate from the default skeleton implementation. Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart

Rainer Hoerbe schrieb am 23.09.2016 um 09:40:
I created an issue on github.
Please note that lxml doesn't use issue tracking on github. The bug tracker is here: https://bugs.launchpad.net/lxml This should fix your problem, though: https://github.com/lxml/lxml/commit/fd4a5c5d23fbb7e7575f82bd6f1b027bd5c17038 Thanks for the report. Stefan
participants (3)
-
Holger Joukl
-
Rainer Hoerbe
-
Stefan Behnel