My mind is puny.
April 23, 2009 6:32 AM Subscribe
Could someone please point me in the right direction?
I have an xml document that has been extended, and I need to override the xslt that transforms it to html with an import, but I have no idea where to start.
The old xml document looks (simplified) like this:
I'll start learning it soon, but I need to get this done now...
The old xml document looks (simplified) like this:
<document> <title>Title Text</title> <para>Paragraph Text</para> </document>There was a whole body of xslt dealing with this (I'm talking thousands of lines of code here, it's really much more complicated than my stupid example leads to believe). Now the dtd has been extended and the xml looks as follows:
<document> <title> <container1> <container2> <block attr="1">Title Text for a</block> <block attr="2">Title Text for b</block> </container2> </container1> </title> <para> <container1> <container2> <block attr="1">Paragraph Text for a</block> <block attr="2">Paragraph Text for b</block> </container2> </container1> </para> </document>The idea is to now generate 2 html documents, one for case a and one for case b. So the whole body of xslt dealing with this document still applies, only I need to import an additional xslt file that tells the original xslt to ignore <container1> and <container2> and <block attr="1|2"> and then proceed as usual. But how? I've only hacked a bit of xslt up till now, so while I know how it works I don't actually have a solid base to work from.
I'll start learning it soon, but I need to get this done now...
Actually, even if the document isn't as flat as in your example, if the only change in the dtd is that some elements from the original dtd have the container1, container2 and block child elements added to them, you could do as I explained, and it should be reasonably easy.
Does every element from the old dtd have the new child elements added? Have there been any other changes to the dtd at all?
posted by syzygy at 7:49 AM on April 23, 2009
Does every element from the old dtd have the new child elements added? Have there been any other changes to the dtd at all?
posted by syzygy at 7:49 AM on April 23, 2009
Response by poster: Your solution is simple and intuitive, but unfortunately due to software restrictions I can run the stylesheet only once, and there cannot be any intermediate files. There are elements that do not have this container added, and no, there are no other changes.
Basically what I need is override the xslt that goes (for example)
[template match="title"]
[apply-templates select="*|text()"]
[/template]
to:
[template match="title"]
[apply-template name="<name of the template that discards the containers and only keeps the content of block 1 or 2>"]
[/template]
or not? Am I thinking wrong? And if I'm right, basically my question is "what would that template look like?
posted by Skyanth at 8:18 AM on April 23, 2009
Basically what I need is override the xslt that goes (for example)
[template match="title"]
[apply-templates select="*|text()"]
[/template]
to:
[template match="title"]
[apply-template name="<name of the template that discards the containers and only keeps the content of block 1 or 2>"]
[/template]
or not? Am I thinking wrong? And if I'm right, basically my question is "what would that template look like?
posted by Skyanth at 8:18 AM on April 23, 2009
Response by poster: (sorry, that should of course be "call template", not "apply template" in that last bit.)
posted by Skyanth at 8:25 AM on April 23, 2009
posted by Skyanth at 8:25 AM on April 23, 2009
Response by poster: Argh.
syzygy helped me out over MeMail, and the solution was too embarrassingly simple to post here. Thanks again, syzygy!
posted by Skyanth at 10:40 AM on April 23, 2009
syzygy helped me out over MeMail, and the solution was too embarrassingly simple to post here. Thanks again, syzygy!
posted by Skyanth at 10:40 AM on April 23, 2009
This thread is closed to new comments.
If your document is really this flat, and every element has the child elements exactly as you've listed them, I think you'll have to write two new XSLT documents. They will have similar functionality, but one will out put case a and one will out put case b. What you'd want here is XSLTa strips the container1, container2 and block elements, but keeps the contents of block attr="1". XSLTb would do the same, except that it would keep the contents of block attr="2".
So, in the end, you'd transform your newly structured XML document into two documents that have the old structure, then you'd transform each of those documents with your original XSLT.
posted by syzygy at 7:45 AM on April 23, 2009