Subject: RE: [xsl] sorting using a precalculated value From: Stephane Bailliez <sbailliez@xxxxxxxxxxxxxx> Date: Wed, 28 Mar 2001 17:23:04 +0100 |
Nice. I did not think about doing it this way. I think I will use the temporary tree solution anyway because I need to do this in several contexts, so I'd better navigate into this temporary tree. I will try to put a few keys here and there at the same time to ease my job of grouping as well. Thanks for your input Chris. -- Stéphane Bailliez Software Engineer, Paris - France iMediation - http://www.imediation.com Disclaimer: All the opinions expressed above are mine and not those from my company. > -----Original Message----- > From: Chris Bayes [mailto:Chris@xxxxxxxxxxx] > Sent: Wednesday, March 28, 2001 5:39 PM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: [xsl] sorting using a precalculated value > > > Stephane, > This will give you the desired output > > <?xml version="1.0" encoding="utf-8"?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method = "text" /> > <xsl:template match="classes"> > <xsl:apply-templates> > <xsl:sort select="@name"/> > <xsl:with-param name="name" select="@name" /> > </xsl:apply-templates> > </xsl:template> > <xsl:template match="class"> > <xsl:param name="name" /> > <xsl:choose> > <xsl:when test="parent::class"> > <xsl:value-of > select="concat($name, '.', @name)" > /><xsl:text> </xsl:text> > </xsl:when> > <xsl:otherwise> > <xsl:value-of select="@name" > /><xsl:text> </xsl:text> > </xsl:otherwise> > </xsl:choose> > <xsl:apply-templates> > <xsl:sort select="@name"/> > <xsl:with-param name="name"> > <xsl:choose> > <xsl:when test="parent::class"> > <xsl:value-of > select="concat($name, '.', @name)" /> > </xsl:when> > <xsl:otherwise> > <xsl:value-of > select="@name" /> > </xsl:otherwise> > </xsl:choose> > </xsl:with-param> > </xsl:apply-templates> > </xsl:template> > </xsl:stylesheet> > > Wether it will fit in with what you are trying to do is > another matter. > > Ciao Chris > > XML/XSL Portal > http://www.bayes.co.uk/xml > > > >-----Original Message----- > >From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > >[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Stephane > >Bailliez > >Sent: 28 March 2001 15:11 > >To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > >Subject: [xsl] sorting using a precalculated value > > > > > >I have the following XML: > > > ><classes> > > <class name="OuterClass1"> > > <class name="InnerClass"/> > > </class> > > <class name="AOuterClass"/> > ></classes> > > > >I want to have the following output (ie, class name must be > built and the > >whole stuff sorted) > > > >AOuterClass > >OuterClass1 > >OuterClass1.InnerClass > > > >to build the class name I'm using: > > > ><xsl:template match="class" mode="class.name"> > > <xsl:if test="parent::class"> > > <xsl:apply-templates select="parent::class" mode="class.name"/> > > .<xsl:value-of select="@name"/> > > </xsl:if> > > <xsl:if test="not(parent::class)"> > > <xsl:value-of select="@name"/> > > </xsl:if> > ></xsl:template> > > > >However, I'm a little bit stuck here because I cannot do the > following: > > > ><xsl:templates match="classes"> > > <xsl:for-each select=".//class"> > > <xsl:variable name="class.name> > > <xsl:apply-templates select="." mode="class.name"/> > > </xsl:variable> > > <xsl:sort select="$class.name"/> <!---- Not possible -----> > > <xsl:apply-templates select="." mode="class.name"/> > ></xsl:template> > > > >Since I need to do this sorting/name resolution many times, > in different > >contexts, it would be nice to precalculate all this via > keys, but I'm not > >sure I can do this. > > > >If someone has an idea how to do this, I'd be glad to know. > I'm pretty sure > >it's simple, I'm simply missing something. > > > >Thanks a lot. > > > >-- > > Stéphane Bailliez > > Software Engineer, Paris - France > > iMediation - http://www.imediation.com > > Disclaimer: All the opinions expressed above are mine and not > >those from my > >company. > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > > > > 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 -> |
---|---|---|
Re: [xsl] sorting using a precalcul, David Carlisle | Thread | [xsl] Embedding HTML in XML?, Eric Vitiello |
RE: [xsl] template accepting variab, Alex Reuter | Date | RE: [xsl] XSL, Peter . FLYNN |
Month |