1

I am developing an XSLT for adding value to some of my nodes which are empty. It works if the nodes are within a single or two parents e.g.

<?xml version="1.0" encoding="UTF-8"?>

      <VehicleDataCustom>
         <VehicleDataCustomHeader>
            <Commessa>SSP100</Commessa>
            <RecordType />
            <AttivitaAnnullamento />
         </VehicleDataCustomHeader>
      </VehicleDataCustom>

Here is my XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="AttivitaAnnullamento[not(node())]">
        <xsl:copy>yes</xsl:copy>
    </xsl:template>
</xsl:stylesheet>

It cleanely puts a yes in my resulting XML as follows -

<?xml version="1.0" encoding="UTF-8"?><VehicleDataCustom>
         <VehicleDataCustomHeader>
            <Commessa>SSP100</Commessa>
            <RecordType/>
            <AttivitaAnnullamento>yes</AttivitaAnnullamento>
         </VehicleDataCustomHeader>
      </VehicleDataCustom>

But if my XML has the following structure, it does nothing -

<?xml version="1.0" encoding="UTF-8"?>
<ProcessVehicleDataCustom xmlns="http://schema.test.com/Testing/2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.test.com/2.2.0/Testing http://schema.test.com/2.2.0/Testing/BODs/Developer/ProcessVehicleDataCustom.xsd" releaseID="2">
      <VehicleDataCustom>
         <VehicleDataCustomHeader>
            <Commessa>SSP100</Commessa>
            <RecordType />
            <AttivitaAnnullamento />
         </VehicleDataCustomHeader>
      </VehicleDataCustom>
</ProcessVehicleDataCustom>

Not sure what's wrong with this format. Is there any way to handle this tag? Am I missing something?

Techidiot
  • 1,921
  • 1
  • 15
  • 28
  • 1
    This is a *namespace* issue, and it has been answered many times - see, for example: http://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628 – michael.hor257k May 13 '16 at 13:46

1 Answers1

0

SOLVED-

I was able to get it done by using the following XSLT -

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:met="http://schema.test.com/Testing/2"
exclude-result-prefixes="met">
<xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
<xsl:template match="met:VehicleDataCustom/met:VehicleDataCustomHeader/met:AttivitaAnnullamento[not(node())]">
        <xsl:copy>attiv</xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Hope that helps someone.

Techidiot
  • 1,921
  • 1
  • 15
  • 28