Subject: Re: [xsl] transforming XSLT files to use XSLT3 features From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 11 Feb 2023 12:39:34 -0000 |
On 11/02/2023 11:34, Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx wrote:The approach is limited by its use of template matches and regular expressions. For some reason, I donbt feel inclined to write an XPath grammar parser in XSLT. But still, some low-hanging fruit can be obtained.
Have a look at Gunther Rademacher's REx Parser Generator https://www.bottlecaps.de/rex/
It can be used to generate an XSLT parser for XPath 2. (I've used it extensively in the past for analysing XPath 3 expressions.)
An alternative, if your XSLT platform supports it, is to use an InvisibleXML parser https://invisiblexml.org/ There is an iXML grammar forB XPath3.1 available (https://github.com/invisibleXML/ixml/tree/master/samples/XPath) which will also parse XPath2. You may be able to experiment with this using Martin Honnen's XSLT3 Fiddle (https://martin-honnen.github.io/xslt3fiddle/) which supports invisibleXML parsing functions.
Note that the entry page to the XSLT 3 fiddle with support for Invisible XML through John's library is not https://martin-honnen.github.io/xslt3fiddle/ but https://martin-honnen.github.io/xslt3fiddle/index-iXML.html. There you could then make use of the XPath 3.1 grammar with code like e.g.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" B version="3.0" B xmlns:xs="http://www.w3.org/2001/XMLSchema" B xmlns:jwL="https://github.com/johnlumley" B exclude-result-prefixes="#all" B expand-text="yes">
B <xsl:include href="https://martin-honnen.github.io/xslt3fiddle/xslt/jwiXML.processor.xsl"/
B <xsl:param name="xpath31-grammar-uri" as="xs:string">https://raw.githubusercontent.com/invisibleXML/ixml/master/sam ples/XPath/XPath.reducedTree.ixml</xsl:param>
B <xsl:variable name="parsed-xpath31-grammar" select="jwL:compileGrammar(unparsed-text($xpath31-grammar-uri))"/>
B <xsl:template match="xpath"> B B B <xsl:copy> B B B B B <input>{.}</input> B B B B B <parsed-tree>{jwL:parse($parsed-xpath31-grammar, .)?tree => serialize(map{'method':'xml','indent':true()})}</parsed-tree> B B B </xsl:copy> B </xsl:template>
<root> B <examples> B B B <xpath>random-number-generator()?permute(1 to 5)</xpath> B </examples> </root>
<root> B <examples> B B B <xpath><input>random-number-generator()?permute(1 to 5)</input><parsed-tree><![CDATA[<XPath> B B <PostfixExpr> B B B B B <FunctionCall> B B B B B B B B <UnprefixedName LocalPart="random-number-generator"/> B B B B B B B B <ArgumentList/> B B B B B </FunctionCall> B B B B B <Lookup> B B B B B B B B <KeySpecifier Name="permute"/> B B B B B </Lookup> B B B B B <ArgumentList> B B B B B B B B <RangeExpr> B B B B B B B B B B B <IntegerLiteral>1</IntegerLiteral> B B B B B B B B B B B <IntegerLiteral>5</IntegerLiteral> B B B B B B B B </RangeExpr> B B B B B </ArgumentList> B B </PostfixExpr> </XPath>]]></parsed-tree></xpath> B </examples> </root>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] transforming XSLT files t, John Lumley john@xxx | Thread | Re: [xsl] transforming XSLT files t, Joel Kalvesmaki dire |
Re: [xsl] transforming XSLT files t, John Lumley john@xxx | Date | Re: [xsl] transforming XSLT files t, Joel Kalvesmaki dire |
Month |