Jump to content

XSLT Preprocessing


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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...