This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: sorting using a precalculated value
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] sorting using a precalculated value
- From: "Chris Bayes" <Chris at Bayes dot co dot uk>
- Date: Wed, 28 Mar 2001 16:38:34 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
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@lists.mulberrytech.com
>[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Stephane
>Bailliez
>Sent: 28 March 2001 15:11
>To: xsl-list@lists.mulberrytech.com
>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