Jump to content

XSLT Preprocessing


Donar
 Share

Recommended Posts

Good day, My XSLT transforms XLM pages into HTML pages. Now I am stuck with a problem, that seems not trivial to me. I would appreciate a pointer into the right direction. I want to reduce the number of lines I have to write in my original XML files. What I want, is something like a XSLT preprocessor, translating some XML tags into a group of other XML tags, before XSLT processes them. If at all possible, I want to keep the replaced as well as the replacing lines in the same XML document (so, no include-file-style solutions). Example: Oftentimes, my XML files contain repetitive multiple lines, e.g. the following simplified snippet:

<img>	<url>a_midi.jpg</url></img><img>	<url>b_midi.jpg</url></img><img>	<url>c_midi.jpg</url></img>

It would be great, if I could include these multiple lines into a macro tag, placed somewhere near the beginning of the XML file, like this:

<macro id="name_a">	<img>		<url>a_midi.jpg</url>	</img>	<img>		<url>b_midi.jpg</url>	</img>	<img>		<url>c_midi.jpg</url>	</img></macro>

Instead of repeating the initial lines over and over again at various places, I'd just use something like:

 <use_macro id="name_a"/>

Now, I certainly can instruct the XSLT to process the template <macro> matching the name "name_a", when it encounters the <use_macro> tag. However, this is not what I want. The reason is, that above <img> tags are themselves contained in another surrounding tag, say <multi_img>. The XSLT processing this <multi_img> tag considers a lot of other tags contained in itself, which dictate how exactly the XML is transformed into HTML (and sometimes the <img> tags even need to be processed multiple times in different manners.) Hence, what I am looking for, is a way to (1) first transform the XML <use_macro> into the XML contained in the <macro> tag; (2) and then process the resulting XML with XSLT as if there was no <use_macro> tag at all in the first place. Possibly the solution is obvious and I am just overworked, but I can't find what I need (even not after spending some time with Jeni Tennison's "XSLT and XPath / On the edge"). I appreciate pointers (also to the appropriate chapter in Tennison's book), or just the statement "it can not be done". Thanks in advance. Regards,Donar

Edited by Donar
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...