sorting XML by multiple elements

R

R

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
 
M

Martin Honnen

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>
 
R

R

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

R

sorry i've just found the solution:

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

;)

best regards
R
 
M

Martin Honnen

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]" />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top