Jump to content

Two Namespaces to one xmlns


Guest mooncow33

Recommended Posts

Guest mooncow33

We are importing and parsing xml documents from a third party. They have two formats (namespaces) that we import, however both these namespaces have the same tags, or at least they do as far as we are concerned. What this means is that we are forced to have two identical .xslt files, the only difference is in the xmlns declarations:

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:elci="LocalMUNI"

vs

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:elci="LocalNTC"

So my question is, is there a way to map xmlns:elci to both "LocalMUNI" and "LocalNTC" so that I can merge these documents into one?

Link to comment
Share on other sites

Which XSLT version do you use? With XSLT/XPath 2.0 you can simply do e.g.<xsl:template match="*:foo">or<xsl:for-each select="*:foo">to process elements with local name "foo" in any namespace so that way you can easily write one stylesheet that processes elements independent on the namespace.Even with XSLT 1.0 you could do e.g.

<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:ns1="LocalMUNI"  xmlns:ns2="LocalNTC"  exclude-result-prefixes="ns1 ns2">  <xsl:template match="ns1:foo | ns2:foo">	...  </xsl:template></xsl:stylesheet>

if you want to write the same code for elements from different namespaces.A different option is to simply write a second stylesheet you run before your main stylesheet, the second stylesheet will then first change or remove the namespace as needed.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...