XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] XSLT/XQuery polyglot

Polyglot script q.xml does real computation. It evaluates "isXPath1" XPath expression I created based on a longer one from Jonathan Robie. It outputs "false" for XPath 2.0 (Saxon XQuery, Saxon XSLT and DataPower XQuery processor) and "true" for XPath 1.0 (DataPower XSLT processor):

$ cat q.xml
<foo xsl:version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="(4=5)=/.."/>{(4=5)=/..}
</foo>
$

Here are the 4 executions:
$ java net.sf.saxon.Query -q:q.xml ; echo
<?xml version="1.0" encoding="UTF-8"?><foo xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="2.0"><xsl:value-of select="(4=5)=/.."/>false</foo>
$
$ java net.sf.saxon.Transform -xsl:q.xml -s:q.xml ; echo
<?xml version="1.0" encoding="UTF-8"?><foo>false{(4=5)=/..}
</foo>
$
$ xj --xquery q.xml dummy.xml ; echo
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="2.0"><xsl:value-of select="(4=5)=/.."/>false</foo>
$
$ xj q.xml dummy.xml ; echo
<?xml version="1.0" encoding="UTF-8"?>
<foo>true{(4=5)=/..}
</foo>
$

["xj" DataPower command line XSLT/XQUery processor is not available to customers, they have to use DataPower appliance]


Mit besten Gruessen / Best wishes,

Hermann Stamm-Wilbrandt
Compiler Level 3 support & Fixpack team lead
IBM DataPower Gateways (⬚ᵈᵃᵗᵃ / ⣏⠆⡮⡆⢹⠁⡮⡆⡯⠂⢎⠆⡧⡇⣟⡃⡿⡃)
https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/
https://twitter.com/HermannSW/ https://stamm-wilbrandt.de/GraphvizFiddle/
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

Inactive hide details for Hermann Stamm-Wilbrandt---16.12.2015 04:22:19---Hi, I did some searches but found no other mentioningHermann Stamm-Wilbrandt---16.12.2015 04:22:19---Hi, I did some searches but found no other mentioning of this.

From: Hermann Stamm-Wilbrandt/Germany/IBM@IBMDE
To: xml-dev@lists.xml.org
Date: 16.12.2015 04:22
Subject: [xml-dev] XSLT/XQuery polyglot





Hi,

I did some searches but found no other mentioning of this.


From

https://en.wikipedia.org/wiki/Polyglot_(computing)
... a polyglot is a computer program or script written in a valid form of
multiple programming languages, which performs the same operations or output
independent of the programming language used to compile or interpret it. ...



Simple "poly.xml" is a XSLT/XQuery polyglot (same output):
$ java net.sf.saxon.Query -q:poly.xml > xq
$ java net.sf.saxon.Transform -xsl:poly.xml -s:poly.xml > xsl
$ diff xq xsl
$ cat xq ; echo
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" version="2.0"><xsl:template match="/"><xsl:copy-of select="document('')"/></xsl:template></xsl:stylesheet>
$
$ cat poly.xml
<xsl:stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" version="2.0"><xsl:template match="/"><xsl:copy-of select="document('')"/></xsl:template></xsl:stylesheet>
$



I found no option to avoid output of xml declaration in Saxon XQuery as
command line option.


declare option saxon:output "omit-xml-declaration=yes";
would need to stay before output and break XSLT that way.


At least the XSLT part would be a cheating quine at most only:

https://en.wikipedia.org/wiki/Quine_(computing)#.22Cheating.22_quines


Mit besten Gruessen / Best wishes,

Hermann Stamm-Wilbrandt
Compiler Level 3 support & Fixpack team lead
IBM DataPower Gateways     (⬚ᵈᵃᵗᵃ / ⣏⠆⡮⡆⢹⠁⡮⡆⡯⠂⢎⠆⡧⡇⣟⡃⡿⡃)

https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/     
https://twitter.com/HermannSW/     https://stamm-wilbrandt.de/GraphvizFiddle/
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294





[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS