Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   sorting XML by multiple elements (http://www.velocityreviews.com/forums/t296005-sorting-xml-by-multiple-elements.html)

R 05-30-2006 12:54 PM

sorting XML by multiple elements
 
Hi All,

I have problem with sorting nodes I want sort them by columns c1, c2
also I have node <root><sort ActiveField="c0"/></root>

ActiveField attribute is set by user.

I'm sorting 'row' nodes, 'row' has c0, c1, c2, ..., cn child elements

I wrote:
<xsl:for-each select="row">
<xsl:sort select="concat(/root/sort/@ActiveField, c1, c2)"/>
// do somethning
</xsl:for-each>

but I doesn't work - is it allowed to use XPath inside concat function?

how can it be achived to sort 'row' elements by multiple elements?

thanks in advance for any help
best regards
R


Martin Honnen 05-30-2006 12:59 PM

Re: sorting XML by multiple elements
 


R wrote:


> <xsl:for-each select="row">
> <xsl:sort select="concat(/root/sort/@ActiveField, c1, c2)"/>
> // do somethning
> </xsl:for-each>
>
> but I doesn't work - is it allowed to use XPath inside concat function?
>
> how can it be achived to sort 'row' elements by multiple elements?


You can have multiple xsl:sort elements inside the xsl:for-each e.g.
<xsl:for-each select="row">
<xsl:sort select="c1" />
<xsl:sort select="c2" />
<!-- ... -->
</xsl:for-each>

--

Martin Honnen
http://JavaScript.FAQTs.com/

R 05-30-2006 04:45 PM

Re: sorting XML by multiple elements
 
thanks,

If you could help me out with XPath expression in xsl:sort

given
<root><sort ActiveField="name"/></root>

<xsl:for-each select="row">
<xsl:sort select="/root/sort/@ActiveField" />
<xsl:sort select="c1" />
<xsl:sort select="c2" />
<!-- ... -->
</xsl:for-each>

doesn't work - probably in place of /root/sort/@ActiveField string
'name' is passed
so every row is sorted by conts 'name' (not value of name element)
and values of c1 and c2 elements

when I hardcode the child element this way:

<xsl:for-each select="row">
<xsl:sort select="name" />
<xsl:sort select="c1" />
<xsl:sort select="c2" />
<!-- ... -->
</xsl:for-each>

it works fine - how can the same result be achieved with
/root/sort/@ActiveField attribute
pointing to the name of the first sort element?

thanks in advance for any hints
best regards
R


R 05-30-2006 04:56 PM

Re: sorting XML by multiple elements
 
sorry i've just found the solution:

<xsl:sort select="*[name() = /root/sort/@ActiveField]"/>

;)

best regards
R


Martin Honnen 05-30-2006 05:32 PM

Re: sorting XML by multiple elements
 


R wrote:


> If you could help me out with XPath expression in xsl:sort
>
> given
> <root><sort ActiveField="name"/></root>
>
> <xsl:for-each select="row">
> <xsl:sort select="/root/sort/@ActiveField" />


I think you want
<xsl:sort select="*[local-name() = /root/sort/@ActiveField]" />





--

Martin Honnen
http://JavaScript.FAQTs.com/


All times are GMT. The time now is 04:42 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.