0

I have a situation where I am processing XML that conforms to one of two DTDs. Is there a way to use XSL to evaluate the DTD specified in the XML file and then call an appropriate XSLT for that DTD? I'm imaging that I would have, for example, dtd1.xsl and dtd2.xsl, where each one had been developed to transform XML conforming to two different DTDs. Another XSL file would first look at the DTD of the incoming XML file and based on that determine if dtd1.xsl or dtd2.xsl should be used to transform the XML.

I understand that there are many ways to do this in code outside of XSL, but I am looking specifically for an XSL solution.

Nick A. Watts
  • 819
  • 10
  • 16
  • Can you post an example of your input XML? It's entirely possible to use the same XSL for both kinds of input - maybe that's easier than what you have in mind. – Tomalak Jan 17 '13 at 20:47
  • I was working on that combined approach until I found out that there were two existing XSLTs that have been honed over several years (one for each DTD). So now I'm looking for an approach that will let me use these two XSLTs without merging them together or otherwise changing them....if that is possible. – Nick A. Watts Jan 17 '13 at 20:51
  • I'm afraid that there is no interface to read the DTD in XSLT, not even in version 2.0. You are out of luck - unless you can identify a discriminating element or structure, some XPath that can detect what document you have, for example. – Tomalak Jan 17 '13 at 20:56
  • There are definitely different, unique paths between the DTDs that could be used to differentiate them. Given that, how would I be able to load and use one XSL over another? Is that part even possible? – Nick A. Watts Jan 17 '13 at 21:06
  • It does not look like it. See http://stackoverflow.com/q/4471992/18771 – Tomalak Jan 17 '13 at 21:12
  • In case the DTDs describe completely different documents (no node names are the same), then you can simply have one XSLT transformation/stylesheet that contains templates for processing instances of either of the DTDa. Simply have templates that match the names of the nodes. – Dimitre Novatchev Jan 17 '13 at 23:09

0 Answers0