[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XPath 2.0 expression that detects a cycle of refe

Subject: Re: XPath 2.0 expression that detects a cycle of references?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 29 Mar 2016 08:57:23 -0000
Re:  XPath 2.0 expression that detects a cycle of  refe
On 29.03.2016 10:46, Michael MC<ller-Hillebrand mmh@xxxxxxxxx wrote:
I think you need to write a recursive function to detect cycles in a graph, and XPath 2.0 does not have sufficient power for this. It can of course be done in XSLT or XQuery. It can possibly be done in XPath 3.0, though because XPath 3.0 functions are anonymous, recursion is tricky.

Well, how would that kind of trick look like?

This is my version of a recursive function for Roger's problem (assuming there can be multiple elements <for-more-info>):

<xsl:function name="my:CycleFound" as="xs:boolean">
   <xsl:param name="this" as="element()?"/>
   <xsl:param name="visited" as="xs:string*"/>
   <xsl:variable name="refId" select="$this/for-more-info/@idref" as="xs:string*"/>
   <xsl:variable name="refTgt" select="$this/../item[@id = $refId]" as="element()*"/>

   <xsl:sequence select="
     if (not(exists($refTgt))) then false()
     else if ($refId = $visited) then true()
     else some $e in $refTgt satisfies my:CycleFound($e, ($visited, $e/@id))
     "/>
</xsl:function>

I have no idea how one would have to handle this using XPath 3b& any suggestions?

Dimitre has an article on using two anonymous function together with "let", to implement the recursion:


https://dnovatchev.wordpress.com/2012/10/15/recursion-with-anonymous-inline-functions-in-xpath-3-0-2/


--- Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprC<ft. https://www.avast.com/antivirus

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.