xml - XPath Custom Sort Expression -


i'm sorting xsl list using xpath.

i want sort chronologically, easy-- list items have duplicate titles , want grouped together, if newer. instance:

list item (created 4/19)

list item b (created 4/18)

duplicate list item b (created 4/21)

list item c (created 4/17)

--the key here ensuring "duplicate list item b" appears beneath original, though it's newest.

right now, expression consists of "@created" displaying items in descending order. need expression says "sort creation date unless title contains word 'duplicate' - in case, sort alphabetically"

can propose custom xpath expression achieves this?

thanks.

edit: here window where' i'd enter xpath expression. again, 2 rows need worry @title , @created_x0020_date

pic

without code go on i'm going make lot of assumptions. given following xml block:

<data>   <block created="20160419" label="a"/>   <block created="20160418" label="b"/>   <block created="20160421" label="b"/>   <block created="20160417" label="c"/> </data> 

you need use keys work. assuming xslt 1.0 way compatible whichever using.

<xsl:key name="labels" match="/data/block" use="@label" />  <xsl:template match="/">     <html lang="en">         <head></head>         <body>             <xsl:for-each select="/data/block[generate-id(.) = generate-id(key('labels', @label))]">                 <xsl:sort select="@created" data-type="number"/>                 <xsl:for-each select="key('labels', @label )">                     <xsl:sort select="@created" data-type="number"/>                      <p><xsl:value-of select="@label"/> - <xsl:value-of select="@created"/></p>                 </xsl:for-each>             </xsl:for-each>         </body>     </html> </xsl:template> 

basically we're doing here creating key loop on each block based on distinct @label value, sorted @created value. there, loop again on each block using current @label variable , sort once more created date.

this gives me following output:

<p>c - 20160417</p> <p>b - 20160418</p> <p>b - 20160421</p> <p>a - 20160419</p> 

obviously rough, , doesn't use templates should, explains concepts enough able understand going on , translate own code!


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -