Is it possible to use a different HTML layout for the same XSLT stylesheet?
I have been reading up on XSLT and most examples i see show that the HTML code is actually embedded within the stylesheet.
Is it possible to use the same stylesheet for more than one HTML layout? (I am thinking similar to how Velocity works – i.e. multiple HTML files can be processed using the same Velocity tags).
I am using the Java Xalan processor to process the XSLT.
Edit
I have tried @Dimitre Novatchev approach below and it works perfectly.
The only thing is how would i handle looping through elements? For example, if the xml document is modified to be:
<person>
<fname>John</fname>
<lname>Smith</lname>
<age>25</age>
<age>33</age>
<age>55</age>
</person>
How can i iterate through each of the age elements?
Here is what i tried on the HTML template but i didnt see any difference:
<html xmlns:gen="my:tranform-generated">
<body>
<h1>Hi <gen:fname/> <gen:lname/>!</h1>
You are <gen:age/> years old.
<gen:for-each select="/person/age">
<gen:age/>,
</gen:for-each>
</body>
</html>
Expected output
I would like the output of the above to be
Hi JohnSmith!
You are 25 years old.
25, 33, 55
Yes, this is a very powerful technique, whcih I call “fill-in the blanks”.
Here is a very short example:
Skeleton 1:
Skeleton 2:
The XSLT transformation is passed as an external parameter the Uri of the “skeleton to use” and it copies all nodes “as-is” with the exception of the specially-named elements (whose names are in the special namespace “my:tranform-generated”). These are substituted by the result of the templates that match them in the XSLT transformation.
Here is an example of such a transformation:
when this transformation is applied on this XML document:
the wanted, correct result (using Skeleton1.xml) is produced:
When the same transformation is applied on the same XML document, but the external parameter
$pSkeletonpassed to it has the value of"file:///c:/temp/delete/Skeleton2.xml", then again we get the wanted result (a formatted Skeleton2):Update:
Here is an example how to handle iteration — as requested by the OP:
Skeleton3.xml:
When the transformation above is applied on the this XML document:
the wanted, correct result is produced: