I have document grandchild.xml whose result after being processed with granchild.xsl must be forwarded to child.xsl, then it must be finally processed and output by parent.xsl.
I have tried adding an xml-stylesheet
element to the result document, expecting it to processed using by the referenced XSL stylesheet, but nothing happened.
What is the correct declaration to accomplish this task? I have searched a lot on Internet, with no results.
Unless anybody knows any better, I believe the ability to recursively process XSLT output on a browser is impossible.
To prove it, I have just tried the following in IE8, FF14 and Chrome...
level1.xml
level1.xsl
level2.xsl
The result from all 3 browsers is simply to display
Level 2: Level 1 Data
.Here is an example of multi-pass transformation within a browser:
Let us have this source XML document:
Let us have these two XSLT transformations:
MultiPassBrowser1.xsl
and
MultiPassBrowser2.xsl
The first transformation copies the XML document "as-is", but with the string value of every
num
element multiplied by 2.The second transformation copies the XML document "as-is", but with the string value of every
num
element incremented.If the second transformation is applied on the result of the first, the final values, obtained from the initial
num
elements must be 3, 5, 7, ..., 21.Here is the transformation that glues these two together:
MultiPassBrowser.xsl
The result, when the XML file is opened with both IE, Firefox, Safari and Opera, is the correct, expected one:
Explanation:
The primary stylesheet module (the one referenced in the XML document PI) imports the two stylesheet modules that contain the separate transformations.
The result of the first transformation is captured in the variavle
$vrtfPass1
.In XSLT 1.0 such variable is of the infamous "RTF" (Result Tree Fragment) type and cannot be operated directly (only copying and the
string()
function can be used on an RTF). Here we use a portable variant of thexxx:node-set()
extension function, that works both in IE and in the other four major browsers. This portable extension was first proposed by @DavidCarlisle and the original can be found in his blog.Templates in mode "pass2" are then applied on the node-set, to which we converted, in the step above, the RTF variable. All templates in the second imported stylesheet module are in mode "pass2", thus they are selected for execution.
The final result is produced.