Reputation: 1089
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.
Upvotes: 0
Views: 93
Reputation: 167561
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.
Upvotes: 1