0
votes

I have an xml.

<ClinicalDocuments>

<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="urn:hl7-org:v3/voc"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:axolotl="urn:axolotl-com:pdo">
        <realmCode xmlns="" code="US"/>
        <typeId xmlns="" extension="POCD_HD000040" root="2.16.840.1.113883.1.3"/>
        <templateId xmlns="" root="1.3.6.1.4.1.19376.1.5.3.1"/>
        <templateId xmlns="" root="1.3.6.1.4.1.19376.1.5.3.1.1"/>
        <templateId xmlns="" root="1.3.6.1.4.1.19376.1.5.3.1.1.1"/>
        <templateId xmlns="" root="2.16.840.1.113883.10.20.3"/>
        <templateId xmlns="" root="2.16.840.1.113883.10.20.1"/>
        <templateId xmlns="" root="2.16.840.1.113883.3.88.11.32.1"/>
        <id xmlns="" root="006e50e9-29b5-4ab2-8c0b-202819b39646"/>
blah
blah
</ClinicalDocument>
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="urn:hl7-org:v3/voc"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
blah
blah
.
.
</ClinicalDocument>

</ClinicalDocuments>

xmlns="" is overritting the the main xmlns.

I want to delete all other instances on xmlns="" while keeping the one at the root node "ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="urn:hl7-org:v3/voc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:axolotl="urn:axolotl-com:pdo"

There are many other xmlns="" in the entire xml. Please help.

2
Your question is not clear. First, ClinicalDocument is not the root node. Next, its children are in no-namespace and the xmlns="" decalration is required to make that clear. Do you want move them to their parent's namespace? This will effectively change your XML schema, so think carefully about the consequences before you do.michael.hor257k

2 Answers

1
votes

You can't manipulate namespace declarations directly in XSLT. You should make sure each element in the result tree is in the correct namespace, and the namespace declarations will then be taken care of automatically.

For example, if you don't want xmlns="" to appear on the realmCode element, then you should make sure that you generate the realmCode element in the same namespace as its parent element. That can be done by a template rule such as:

<xsl:template match="realmCode">
  <xsl:element name="{local-name()}" namespace="urn:hl7-org:v3">
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>
0
votes

Just delete all instances of xmlns="". This XML passes validation and xmlns from <ClinicalDocument> wont be overwritten anymore:

<ClinicalDocuments>
    <ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="urn:hl7-org:v3/voc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:axolotl="urn:axolotl-com:pdo">
        <realmCode code="US"/>
        <typeId extension="POCD_HD000040" root="2.16.840.1.113883.1.3"/>
        <templateId root="1.3.6.1.4.1.19376.1.5.3.1"/>
        <templateId root="1.3.6.1.4.1.19376.1.5.3.1.1"/>
        <templateId root="1.3.6.1.4.1.19376.1.5.3.1.1.1"/>
        <templateId root="2.16.840.1.113883.10.20.3"/>
        <templateId root="2.16.840.1.113883.10.20.1"/>
        <templateId root="2.16.840.1.113883.3.88.11.32.1"/>
        <id root="006e50e9-29b5-4ab2-8c0b-202819b39646"/>
blah
blah
    </ClinicalDocument>
    <ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="urn:hl7-org:v3/voc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
blah
blah...
    </ClinicalDocument>
</ClinicalDocuments>