httpwebwitch - 8:46 pm on Jun 28, 2012 (gmt 0)
The task of dynamically generating XSLT with external settings is something best accomplished using a server-side language, such as Java or PHP or Perl or Python or whatever floats yer boat. PHP is actually quite good at it, since you merely need to add <?php echo $depth; ?> where you currently have the number "2"
In situations where the content of the XML isn't sufficient to render it the way I like, I usually abandon XSLT altogether and parse the XML using something like "SimpleXML" [php.net...]
The selective display of certain XML nodes is also easier to do using a server-side parsing, rather than an XSLT solution.
That said, maybe a more sophisticated XPATH in your for-each might be able to select rows where the depth is what you desire. in XSLT.
But that's not the solution I'd recommend.
As a general, personal rule - though I realize many XML/XSLT-focused apps break this rule - I insist that XML is not a *storage engine*. Storing piles of data in XML and treating it like a database is a mistake. Trying to craft the equivalent of a "where clause" in XSLT is not easy, because honestly XSLT isn't the right tool for that kind of thing.
XML is, at its best, a carrier format. Your XML input should contain only what you wish to display, and nothing more. Then the XSLT can be "dumb", and do what it does best - mark up and transform the XML into something that looks nice in an HTML browser.
That means you should re-examine your data access strategy. The data can be stored in a SQL database, and queried to get just the rows you desire. That data can then be assembled as XML, and then pass that XML into your XSLT stylesheet.
Don't take this personally, but it bothers me when people use a wrench to bang in a nail. Using XSLT to filter & sort data is evidence that XML is being used wrong.