tags:

views:

2314

answers:

3

Namespace checking is disabled on the server that handles XSL transformations (because the guy who wrote the XSL didn't understand namespaces). I have to make changes to the XSL but I can't test it because there aren't any namespaces defined ie.

Instead of

 <xsl:template match="ns:element[position()=1]">...

it has

 <xsl:template match="element[position()=1]">...

so it doesn't match any of the elements in the XML because all they're all qualified with namespaces.

I can't test on the server because I don't have access to it. It's no use fix the XSL because then namespace checking will have to be enabled, and that will break all the other transformations.

So what I need to do is find a way of ignoring namespaces during an XSL transformation. I have access to MSXML, XMLSpy (can't find an option in here) and if I really need to I can code something up in C# or a similar language.

As a last resort I can code up a few regexes but I really don't want to go down that route, especially when dealing with XML...

In response to a comment about more details:

It's a Windows 2003 Virtual Server, running an instance a Methode Servlet (www.eidosmedia.com). I don't know what technique this servlet uses to perform XSL transformations. They're ignoring namespaces because the person who originally wrote the XSL didn't understand them, and didn't include them in the XSL. So now all the XSL files (hundreds) don't have namespaces.

It could be an interesting challenge to fix all these files in one go, but that's not what I need right now (and the departmental manager would never agree to it anyway because of the amount of testing involved). All I want to know is if there's a tool (or technique) available that will allow me to take these XSL files as is and use them to transform a corresponding XML document without taking into account namespaces. It seems to me that a tool must exist, because the guy who wrote the original XSL must have used something similar to test the transformations himself.

+3  A: 

You could do a transform to remove all namespaces from your input prior to your "real" transformation. But... I'm not sure if you should do it. It feels ugly.

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  <xsl:template match="*">
    <xsl:element name="{local-name()}" >
      <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
  </xsl:template>  

  <xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
      <xsl:value-of select="." />
    </xsl:attribute>
  </xsl:template>  

</xsl:stylesheet>


Original answer:

Would that be an option?

<xsl:template match="*[local-name()='element' and position()=1]">...

(as comments showed - it wouldn't)

Tomalak
Unfortunately not. As I posted in another comment the match was just an example. There are "select" functions as well.
ilitirit
Apart from the fact that there is some work required... Why shouldn't this work? <apply-templates select="/*[local-name()='foo']/*[local-name()='bar']/">
Tomalak
I can't think of a reason it shouldn't work, but because of the amount of work required I might as well write regexes to remove/insert namespaces. All I want to know is if there's a tool that will allow transformations without namespaces. I already know of other solutions that require work.
ilitirit
I see. I'll let the answer sit here so that others won't make the same suggestion again. I hope passers-by will be reasonable enough not to down-vote.
Tomalak
A: 

How many namespaces are there in the XML being transformed?

If 1 can you temporarily add that namespace as the default namespace of your XSL? Ok that means you might need change the output namespace etc. but once tested you could remove these tweaks.

If there are more than 1 that implies that there are no local name collisions across the namespaces. Could you tweak the test input XML so that all aliases point to the same namespace and then perform the tweak above.

AnthonyWJones
I've counted at least 10 namespaces (it's a SpreadsheetML file). I've already removed the namespaces from one input file, but it's not a good solution because I have to do it each time I test a new file.
ilitirit
Ouch. :( I doubt you'll find a modern self respecting XSL processor that will allow what you need. Sadly I think RegEx scripts are likely your ownly recourse. Save having a stern word with the server owners.
AnthonyWJones
+1  A: 

I'm posting this as an answer because it's too long to fit as a comment.

No XSLT processor that I've ever even heard of allows you to just globally ignore namespaces in the input XML. If you have XSL transforms that are written in ignorance of namespaces, and XML documents that use them, you either have to use the broken servlet to do the transformation, or pre-process the XML documents to remove the namespaces.

The transform Tomalak posted will do that - and unlike using regular expressions, it will do it without screwing up everything else in the XML. And it's not very much work to do that, either. Chaining transforms is pretty easy.

Robert Rossney