[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] How Can I Reference previous XML in Subsequent Iterations?


Subject: Re: [xsl] How Can I Reference previous XML in Subsequent Iterations?
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 18 Apr 2007 17:37:01 +0200

Chris M. wrote:

Yeah, see my previous comment. I think my metaphor of a "control panel" is fairly accurate. The main issues I have with the way XSLT works is with the way states change all the time.

This is a feature. You should twist your thinking 180 degrees ;)


For example, if I want to compare a value to the value of the previous iteration in an xsl:for-each loop, I need to first extract the value and store it in a "variable," as the XPath state changes, and you can't reference it easily in the predicate, which has a state defined by the node being tested at the time.

This is not the way to go. Most likely you would've fixed your problem with a simple xsl:apply-templates instead of for-each, and a simple preceding-sibling::node() for you "variable". Once you seem to need xsl:for-each, it is best to try it with xsl:apply-templates and a matching template instead. This will quickly get you into the "XSLT mind set" instead of the "procedural mind set" (I reckon you see xsl:for-each as something similar to the for-next of procedural languages, which it isn't).



That was Excedrin Headche #1, but I figured it out.

Good. But I think it could've been simpler (but we all went that path the first tries.. ;)



You don't need to. You persist the results to disk or elsewhere. That's all.

That's the $64,000 question. How do I do that?

saxon my.xslt my.xml > output.xml


Please send the money to my bank account: 1234567890


-- Abel



Current Thread
Keywords