Subject: RE: [xsl] Forming a Tree From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Thu, 11 Jul 2002 10:39:29 +0100 |
Where a stylesheet uses select="//x[@y=$z]", it can almost invariably be speeded up significantly by using <xsl:key> and the key() function. Use <xsl:key name="k" match="x" use="@y"/> ... select="key('k', $z)" Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > Venkatesh Sutrave > Sent: 11 July 2002 09:33 > To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Forming a Tree > > > Hi, > I am trying to form a tree on a raw XML, my input XML looks like > - > > <?xml version="1.0"?> > <Root> > <row BookId="1" BookTitle="abc1" TopicId="1" ParentTopicId="1" > TopicTitle="Topic1"/> > <row BookId="1" BookTitle="abc1" TopicId="2" ParentTopicId="1" > TopicTitle="Topic11"/> > <row BookId="1" BookTitle="abc1" TopicId="4" ParentTopicId="4" > TopicTitle="Topic12"/> > <row BookId="1" BookTitle="abc1" TopicId="3" ParentTopicId="2" > TopicTitle="Topic21"/> > > <row BookId="1" TopicId="1" SiteId="1" SortOrder="0" > SiteTitle="Site1" /> > <row BookId="1" TopicId="2" SiteId="2" SortOrder="0" > SiteTitle="Site2" /> > <row BookId="1" TopicId="3" SiteId="3" SortOrder="0" > SiteTitle="Site3" /> > <row BookId="1" TopicId="4" SiteId="4" SortOrder="1" > SiteTitle="Site4" /> > <row BookId="1" TopicId="4" SiteId="1" SortOrder="0" > SiteTitle="Site1" /> > </Root> > > and my XSL is - > > <?xml version='1.0'?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:template match="Root"> > <TreeNodes> > <xsl:apply-templates select="row[@BookTitle and > not(preceding::row/@BookId=@BookId)]" /> > </TreeNodes> > </xsl:template> > > <xsl:template match="row"> > <TreeNode> > <xsl:variable name="node1" select="."/> > <xsl:attribute name="BookId"><xsl:value-of > select="@BookId"/></xsl:attribute> > <xsl:attribute name="Text"><xsl:value-of > select="@BookTitle"/></xsl:attribute> > > <!-- Topic node --> > <xsl:for-each select="//row[@ParentTopicId=@TopicId and > @BookId=$node1/@BookId and @TopicTitle]"> > <TreeNode> > <xsl:variable name="node2" select="."/> > <xsl:attribute name="TopicId"><xsl:value-of > select="@TopicId"/></xsl:attribute> > <xsl:attribute name="ParentTopicId"><xsl:value-of > select="@ParentTopicId"/></xsl:attribute> > <xsl:attribute name="Text"><xsl:value-of > select="@TopicTitle"/></xsl:attribute> > > <!-- Sub-Topic1 --> > <xsl:for-each > select="//row[@ParentTopicId=$node2/@TopicId and > @ParentTopicId!=@TopicId and @BookId=$node1/@BookId and > @TopicTitle]"> > <TreeNode> > <xsl:variable name="node3" select="."/> > <xsl:attribute > name="TopicId"><xsl:value-of select="@TopicId"/></xsl:attribute> > <xsl:attribute > name="ParentTopicId"><xsl:value-of > select="@ParentTopicId"/></xsl:attribute> > <xsl:attribute name="Text"><xsl:value-of > select="@TopicTitle"/></xsl:attribute> > > <!-- Sub-Topic2 --> > <xsl:for-each > select="//row[@ParentTopicId=$node3/@TopicId and > @ParentTopicId!=@TopicId and @BookId=$node1/@BookId and > @TopicTitle]"> > <TreeNode> > <xsl:variable name="node4" > select="."/> > <xsl:attribute > name="TopicId"><xsl:value-of select="@TopicId"/></xsl:attribute> > <xsl:attribute > name="ParentTopicId"><xsl:value-of > select="@ParentTopicId"/></xsl:attribute> > <xsl:attribute > name="Text"><xsl:value-of select="@TopicTitle"/></xsl:attribute> > > <!-- Site --> > <xsl:for-each > select="//row[@BookId=$node4/@BookId and @TopicId=$node4/@TopicId > and @SiteId]"> > <xsl:sort select="@SortOrder" > data-type="number"/> > <TreeNode> > <xsl:call-template > name="SiteDetails"> > <xsl:with-param > name="site" select="."/> > </xsl:call-template> > </TreeNode> > </xsl:for-each> > </TreeNode> > </xsl:for-each> > > <!-- Site --> > <xsl:for-each > select="//row[@BookId=$node3/@BookId and @TopicId=$node3/@TopicId > and @SiteId]"> > <xsl:sort select="@SortOrder" > data-type="number"/> > <TreeNode> > <xsl:call-template > name="SiteDetails"> > <xsl:with-param > name="site" select="."/> > </xsl:call-template> > </TreeNode> > </xsl:for-each> > </TreeNode> > </xsl:for-each> > > <!-- Site --> > <xsl:for-each > select="//row[@BookId=$node2/@BookId and @TopicId=$node2/@TopicId > and @SiteId]"> > <xsl:sort select="@SortOrder" > data-type="number"/> > <TreeNode> > <xsl:call-template name="SiteDetails"> > <xsl:with-param name="site" > select="."/> > </xsl:call-template> > </TreeNode> > </xsl:for-each> > </TreeNode> > </xsl:for-each> > </TreeNode> > </xsl:template> > > <xsl:template name="SiteDetails"> > <xsl:param name="site"/> > <xsl:attribute name="TopicId"><xsl:value-of > select="$site/@TopicId"/></xsl:attribute> > <xsl:attribute name="SiteId"><xsl:value-of > select="$site/@SiteId"/></xsl:attribute> > <xsl:attribute name="Text"><xsl:value-of > select="$site/@SiteTitle"/></xsl:attribute> > </xsl:template> > > </xsl:stylesheet> > > I am applying transformation using .NET classes. > Can the above XSL optimized to gain performance ? > Can I avoid '//row' to achieve the same? > > Thanks in advance. > Venkatesh _________________________________________________________ > There is always a better job for you at Monsterindia.com. > Go now http://monsterindia.rediff.com/jobs > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Forming a Tree, Venkatesh Sutrave | Thread | Re: RE: [xsl] Forming a Tree, Venkatesh Sutrave |
Re: [xsl] Converting Strict XHTML +, Jeni Tennison | Date | [xsl] regarding newline, subbu |
Month |