[xsl] sorting using a precalculated value

Subject: [xsl] sorting using a precalculated value
From: Stephane Bailliez <sbailliez@xxxxxxxxxxxxxx>
Date: Wed, 28 Mar 2001 15:10:51 +0100
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


Current Thread