I have a large collection of XML files which I need to transform using XSLT. The problem is that many of these files were hand-written by different people and they do not use consistent names to refer to the schemas. For example, one file might use:
xmlns:itemType="http://example.com/ItemType/XSD"
where another might use the prefix "it" instead of "itemType":
xmlns:it="http://example.com/ItemType/XSD"
If that's not bad enough, there are several files which use two or three synonyms for the same thing!
<?xml version="1.0"?> <Document xmlns:it="http://example.com/ItemType/XSD" xmlns:itemType="http://example.com/ItemType/XSD" xmlns:ItemType="http://example.com/ItemType/XSD" ...
(there's clearly been a lot of cutting and pasting going on)
Now, because the pattern matching in the XSLT file appears to work on the namespace prefix (as opposed to the schema it relates to) the pattern only matches one of the variants. So if I write something like:
<xsl:template match="SomeNode[@xsi:type='itemType:SomeType']"> ... </xsl:template>
Then it only matches a subset of the cases that I want it to.
Question 1: Is there any way to get the XSLT to match all the variants?
Question 2: Is there any way to remove the duplicates so all the output files use consistent naming?
I naïvely tried using "namespace-alias" but I guess I've misunderstood what that does because I can't get it to do anything at all - either match all the variants or affect the output XML.
<?xsl:stylesheet version="1.0" ... xmlns:it="http://example.com/ItemType/XSD" xmlns:itemType="http://example.com/ItemType/XSD" xmlns:ItemType="http://example.com/ItemType/XSD" ... <xsl:output method="xml" indent="yes"/> <xsl:namespace-alias stylesheet-prefix="it" result-prefix="ItemType"/> <xsl:namespace-alias stylesheet-prefix="itemType" result-prefix="ItemType"/>