Is there a way to ignore namespaces during XSL conversion?

Namespace checking is disabled on a server that handles XSL transformations (because the guy who wrote XSL did not understand the namespace). I have to make changes to XSL, but I cannot verify it because there are no namespaces, that is.

Instead

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

he has

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

so that it does not match any of the elements in XML, because all of them are qualified with namespaces.

I can not check on the server because I do not have access to it. Do not use fix XSL because then namespace validation must be enabled and this will ruin all other conversions.

So what I need to do is find a way to ignore namespaces during XSL conversion. I have access to MSXML, XMLSpy (I can’t find an option here), and if I really need to, I can sign something in C # or in a similar language.

As a last resort, I can code several regular expressions, but I really do not want to go this route, especially when working with XML ...

In response to a comment on more details:

This is a Windows 2003 virtual server that launches an instance of Servet Methode (www.eidosmedia.com). I do not know which method this servlet uses to perform XSL transformations. They ignore namespaces because the person who originally wrote XSL did not understand them and did not include them in XSL. So, now all XSL files (hundreds) do not have namespaces.

It can be an interesting task to fix all these files at once, but that’s not what I need right now (and the department head will never agree to this anyway due to the amount of testing). All I want to know is an accessible tool (or technique) that will allow me to use these XSL files as they are and use them to convert the corresponding XML document without considering namespaces. It seems to me that the tool must exist, because the guy who wrote the original XSL had to use something similar to test the transforms themselves.

+7
xml xslt
source share
4 answers

You can do the conversion to remove all namespaces from your input before your "real" conversion. But ... I'm not sure you should do this. It seems ugly.

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <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:

Will this be an option?

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

(as the comments showed - this is not so)

+5
source share

I am posting this as an answer because it is too long to fit as a comment.

There is no XSLT handler I've ever heard of that allows you to simply globally ignore namespaces in input XML. If you have XSL transformations written in ignorance of namespaces and XML documents that use them, you need to either use the broken servlet to convert, or pre-process the XML documents to remove the namespaces.

A published Tomalak transformation will do this - and, unlike using regular expressions, it will do this without clogging everything else in XML. And it doesn’t really help to do this. Converting conversations is quite simple.

+1
source share

How many namespaces are there in converted XML?

If you can temporarily add this namespace as the default namespace for your XSL? Well, that means you may need to change the namespace on the output, etc., but after testing you can remove these settings.

If the number is greater than 1, then there are no local name conflicts in namespaces. Could you customize the XML test input so that all aliases point to the same namespace and then complete the setup above.

0
source share

try:

 exclude-result-prefixes="" 

Like:

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl"> 
-2
source share

All Articles