Altova Mailing List Archives


Re: [xsl] Recursion (I think)

From: Nicholas Orr <nick@----------->
To:
Date: 9/26/2005 2:32:00 AM
It's ok I've figured it out I think.



I've used a set of templates that call each other and work their way  
down the list, and use parameters to keep the id and name fields that  
I need.  I think it works, and I'll test it on some bigger data sets  
and see how I go.



Cheers,
Nick


    <xsl:template name="GROUPS">

        <xsl:param name="Layoutid" />

        <xsl:param name="Layoutname" />

        <xsl:for-each select="./Object[@type='Field']">

            <xsl:call-template name="RESULTSET">

                <xsl:with-param name="Layoutid" select="$Layoutid"/>

                <xsl:with-param name="Layoutname"  
select="$Layoutname"/>

            </xsl:call-template>

        </xsl:for-each>

        <xsl:for-each select="./Object[@type='GroupButton']/ 
GroupButtonObj">

            <xsl:call-template name="GROUPS">

                <xsl:with-param name="Layoutid" select="$Layoutid"/>

                <xsl:with-param name="Layoutname"  
select="$Layoutname"/>

            </xsl:call-template>

        </xsl:for-each>

    </xsl:template>



On 26/09/2005, at 9:04 AM, Nicholas Orr wrote:



I'm very new to XSL and learning by doing, so thanks in advance for  
responding.  I've got some xml which has come out of a filemaker  
database where you can have a layoutobject that contains either  
field objects or other layoutobjects in a recursive style list :



<FMPReport link="Summary.xml" type="Report"  
creationDate="25/09/2005" creationTime="9:28:42 PM">

    <File name="DDR Sample.fp7" path="/Volumes/BIGHD/Projects/DDR">

        <LayoutCatalog>

            <Layout id="2" name="Layout #2" includeInMenu="True">

                <Object type="GroupButton" flags="0" portal="-1"  
rotation="0">

                    <GroupButtonObj numOfObjs="14">

                        <Object type="GroupButton" flags="0"  
portal="-1" rotation="0">

                            <GroupButtonObj numOfObjs="6">

                                <Object type="Field" flags="0"  
portal="-1" rotation="0">

                                </Object>

                            </GroupButtonObj>

                        </Object>

                    </GroupButtonObj>

                </Object>

                <Object type="GroupButton" flags="0" portal="-1"  
rotation="0">

                    <GroupButtonObj numOfObjs="6">

                        <Object type="Field" flags="0" portal="-1"  
rotation="0">

                        </Object>

                    </GroupButtonObj>

                </Object>

                <Object type="Field" flags="0" portal="-1"  
rotation="0">

                </Object>

            </Layout>

        </LayoutCatalog>

    </File>

</FMPReport>



I'm trying to run a for-each loop on all of the field objects that  
does :



 <xsl:value-of select="./@type"/>



and I can do this fine for any field object at the lowest point in  
the tree by referring to it explicity:



/FMPReport/File/LayoutCatalog/Layout/Object[@type='Field']



which means I can also then reference the parent "Layout" node using :



<xsl:value-of select="../../@id"/>



the problem I have is how do I reference every possible Object 
[@type='Field'] in the tree and still be able to reference the  
parent Layout node?



Thanks,
Nick

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.