0

My question is similar to this question. Except that I would like to have one stylesheet to render (XML to PDF) XML containing either namespaces or not.

Because some of my external system generates XML without namespace and some with namespace and both have similar structure. Is it possible to accomodate one stylesheet to cater both kind of XMLs ? if possible how ?

Thanks for your answers.

Community
  • 1
  • 1
ulab
  • 1,079
  • 3
  • 15
  • 45
  • This question would be easier to answer if you showed concrete examples of the XML input documents, the XSLT stylesheet and the output you expect. Help: http://stackoverflow.com/help/mcve. – Mathias Müller Feb 23 '16 at 12:29
  • sorry I did not want add examples, as the other question in the link was clear enough and has sample. And my question is extension to that. – ulab Feb 23 '16 at 13:42
  • No, this question does not contain examples for your problem, in my opinion. If you show concrete examples, you will also profit more from an answer, because then the answers can be more specific. As you can see, Martin Honnen's answer is quite general now. – Mathias Müller Feb 23 '16 at 16:50

1 Answers1

1

In XSLT 2.0 you can use an asterisk as a wild card for the namespace e.g. <xsl:template match="*:foo"> respectively <xsl:value-of select="*:bar"/>. In XSLT 1.0 you can use the union operator with e.g. <xsl:template match="foo | df:foo"> or <xsl:value-of select="bar | df:bar"/>, as long as a single input contains either namespaced or non-namespaced elements it will work.

As an alternative, you could write one transformation step that does a preprocessing to either add the namespace you expect or to strip it and then use the second transformation step to transform the normalized XML to PDF.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Thanks for your suggestions. I shall try and come back. – ulab Feb 23 '16 at 13:40
  • It had become tedious and the stylesheet is bloated , so ended up having another transformation step to remove namespace before rendering. – ulab Feb 24 '16 at 08:51