I am using XSLT. I know the Inline Function Expressions, Is there some way to declare a named function in xpath expression? because I need the function name to implement a recursive call.
How can I implement a user-defined function with a name in the xpath expression?
445 Views Asked by cmf41013 At
2
There are 2 best solutions below
2
Michael Kay
On
There is no way to declare a named function in XPath; XPath 3.1 only allows anonymous inline functions, and these cannot be recursive. I'm told that there's a way to achieve recursion in anonymous functions using a technique called Y-combinators, but it's fairly mind-boggling and I've never got my head around it. Your best approach, as Martin suggests, is to put this part of the logic at the XSLT level.
Related Questions in XSLT
- Why does a function show up as not defined
- CSV to XML XSLT: How to quote excape
- how to apply templates within xsl:for-each
- Java StreamSource from file in web application project
- How to move an attribute and its value from one element to another
- current index value in xsl
- XSLT list item position issue
- Error including one xslt to another
- xsl:fo how to check new page appears and special ouput
- Limit XSLT Variable to single character
- count the nodes ignoring blank nodes
- Sharepoint 2007 / Jquery - Replace all text on body or render HTML
- XML to XML using XSLT: How to check that element exists in output xml and if not create element with default value
- Visual Studio 2013 XSLT Profile
- Xml to html using xslt of inspect code of VS Projects
Related Questions in XPATH
- XQuery: Select a node in the context of a variable
- Extract value of a input hidden DOMXpath php
- There is no element matching XPath "//html" (Behat\Mink\Exception\DriverException)
- Xpath rule template is missing in SonarQube 5.1
- Xpath having elements with and without prefixes in java
- Traversing with XPath?
- Unable to locate element using cssSelector and xpath
- BaseX XQuery error: root(): no context value bound
- How to add spaces between nodes when using string() on a tree in XPath
- grabbing value from html by xpath in python
- Selenium stops running after click() function runs
- Unable to get images from a link
- Selenium Unable to Perform Operations on SVG Elements
- XSLT expression to check if HTML element exists
- How to eliminate certain elements when scraping?
Related Questions in XSLT-3.0
- can java 1.7 support XSLT 3.0
- Unable to cast the net.sf.saxon.jaxp.TemplatesImpl to serializable
- Saxon can't find package
- JSON to XML with XSLT 3.0 using saxon
- Sort the XML nodes by date in descending order using XSLT 2.0
- XSLT to find all related elements
- Using xsl:evaluate to evaluate value of XPath
- XSLT/Xpath -- sum function performance
- xslt 3 regex in replace function
- Is it possible to embed function (that constructs an element) by value (i.e. anonymous functions/lambdas)
- XSLT Best Way to Sort Duplicate Elements
- Pull data from an element outside of a loop using a common field while streaming
- How to group adjacent xml elements with xslt 2.0 or 3.0?
- controlling serialisation of xml inside JSON
- XSLT 2.0 or XSLT3.0: Group and Merge nodes together based on same value
Related Questions in XPATH-3.1
- Dynamic XQuery using saxon:evaluate not working in Oxygen with an XPath 3.1 type expression?
- Is tokenize($s) the same as tokenize($s, ' ')?
- How does XPath deal with attributes which have conflicting expanded names?
- XPath: How to sort a map?
- XPath 3.1 reference that's complete & succinct
- Is there a way in XPath 3.1 (not XQuery) to sort the results?
- What is the purpose/use of a map in XPath 3.1?
- How can I read the schema (XSD) from Saxon after loading an XML & XSD file?
- How do I load a JSON file into the DOM in Saxon running in Java?
- What is the best way to define all the namespaces for a Saxon XPathCompiler?
- How do I call fn:sort() in Saxon from Java with multiple sort keys
- Is this the best way to get all elements & attributes in an XML file using Saxon?
- XPath 3.1 expression to collect attributes as name/value maps for each selected node
- How can I implement a user-defined function with a name in the xpath expression?
- Creating xsl:result-document with xpath 3.1 fn:transform using saxon 9.9 EE
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
In XSLT I would simply suggest to use
xsl:functionas that way your function has a name and you can call it recursively inside of the function body.As for pure XPath 3, Dimitre explored that path some years ago in https://dnovatchev.wordpress.com/2012/10/15/recursion-with-anonymous-inline-functions-in-xpath-3-0-2/ using
letand higher-order functions (a feature not supported unfortunately in Saxon 9 HE), I think his code there uses a function type syntax not quite aligned with the final spec so his example would need to bewhich could be shortened to
I think given the latest allowed syntax.