Subject: Re: [xsl] Finding paths in Visio XML exports - recursion question From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sat, 27 Sep 2008 12:40:50 -0400 |
Now, I can use an XPath expression to find the first node in the document easily enough (it has a certain property in its data set to "1") and the only way I've been able to find all connected shapes from this one is to use 3 for-each loops: the first over all <Connect>s beginning at the shape itself, the second nested loop over all other endpoints of the <Connect> (there will only ever be one) and the third over all <Shape>s connected to the <Connect>:
<xsl:variable name="thisShapeID" select="./@ID"/> <xsl:for-each select="../../v:Connects/v:Connect[@ToSheet=$thisShapeID and @FromCell='BeginX']"> <xsl:variable name="connectFromSheet" select="./@FromSheet"/> <xsl:for-each select="../v:Connect[@FromSheet=$connectFromSheet and @FromCell='EndX']"> <xsl:variable name="nextShapeID" select="./@ToSheet"/> <xsl:for-each select="../../v:Shapes/v:Shape[@ID=$nextShapeID]">
I had to use the xsl:variables because I couldn't get the equation
[@ID=./@ToSheet], for example, to work (it never matched, any ideas with this?).
Inside the innermost xsl:for-each I recursively call the template which works very well for a straight flow in Visio. However, there can be infinite loops in the flow so I have to first test whether the <Shape> has already been output before recursing. This works.
Also the flows can branch off in multiple directions and each branch needs to be output one at a time (i.e. the nodes before the branch only need to be output once). This also works.
My problem is that I need to output a message (well, an element - eventually this will be XSL-FO) every time the end of a path is reached. This could be because the flow looped back, that is, the recursion is stopped, or it could be because the end of a branch (and therefore outermost for-each) was reached. While this is relatively easy to do, I end up getting multiple copies of the node output because of the multiple levels of recursion.
Does anyone have an idea how to get around this?
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Finding paths in Visio XML ex, Steven Davies | Thread | Re: [xsl] Finding paths in Visio XM, Steven Davies |
[xsl] Finding paths in Visio XML ex, Steven Davies | Date | Re: [xsl] Finding paths in Visio XM, Steven Davies |
Month |