views:

210

answers:

3
<xsl:for-each select="//filenames">
   <xsl:variable name="current_filename" select="."/>
   <xsl:for-each select="
     document(.)//someNode[not(
       . = document($current_filename/preceding-sibling::node())//someNode
     )]
   ">
      <xsl:value-of select="."/>
   </xsl:for-each>
</xsl:for-each>

In the above code (XSLT 1.0), I have a series of documents (//filenames), which I want to open and select some nodes from, unless that node's value equals the value of a same node in all preceding documents.

To get this to work I had to nest two for-each loops, because I have to save the current documents name in a variable in order to select its preceding sibling ($current_filename/preceding-sibling).

This all works, but since I have two nested loops, I'm unable to sort the resulting nodes from all documents as if it were one big sequence. It now sorts the nodes per document if I insert a sorting rule into the first for-each.

Does anyone know a way to achieve this sorting anyway? Maybe a way to avoid having to use the variable and thus the nesting of for-each loops?

A: 

you could put the whole result inside a variable - then using node-set you can then resort the results. see here for examples of using node-set http://www.exslt.org/exsl/functions/node-set/index.html

Josh

Josh
Thanks! But I'm not sure if I'm allowed to use such an extension. Any ideas for a solution without it?
what platform/language are you using?
Josh
What do you mean? It's for an school assignment and should work in a modern browser, but also should only use XSLT 1.0.
+1  A: 

The only way to do that in one step is to store all the nodes in a variable and convert it to a node set with the node-set() extension function. The combined node-set can then be sorted normally.

If you can't use the node-set() function for some reason, you can only break up the operation in two separate transformation steps: 1) output nodes unsorted in a temp document, 2) transform temp document into desired output.

Tomalak
A: 

I've found out how to do this!

By first just selecting all nodes, and sorting them, I was able to then filter out the nodes I didn't want with ! So I changed the order of selecting/sorting. First selecting followed by sorting was impossible, but the other way around works fine! Thanks for your input though :).