![]() |
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 |
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/ |
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 |
Re: sorting XML by multiple elements
sorry i've just found the solution:
<xsl:sort select="*[name() = /root/sort/@ActiveField]"/> ;) best regards R |
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 10:13 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.