Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using XSLT to empty nodes with the exception of specific node.

168284Feb 23 2012 — edited Feb 27 2012
I have XSLT code working which will remove all the empty elements. My user wishes to exempt a specific node, <BypassDateEdits>. I can not figure out the correct syntax to do this.

Source XML is:

<?xml version="1.0" encoding="UTF-8"?>
<IMDSCDB xmlns="http://xml.dod.mil/log/maint/fs/main/4.0.0">
<EndItemTCTOReporting originator="EMOC">
<PartialJobDataDocumentationData/>
<JobControlNumber>
<EventId>052790038</EventId>
<WorkcenterEvent>001</WorkcenterEvent>
</JobControlNumber>
<End/>
<HomeEnterpriseLocationCode>7494</HomeEnterpriseLocationCode>
<CurrentEnterpriseLocationCode>7494</CurrentEnterpriseLocationCode>
<HostUnitDateAndTime>2006-02-23T19:29:37</HostUnitDateAndTime>
<TransactionOrdinalDate>06054</TransactionOrdinalDate>
<ComponentPosition>0</ComponentPosition>
<HowMalfunctionCode>802</HowMalfunctionCode>
<UnitsProduced>01</UnitsProduced>
<StartTime>0800</StartTime>
<StopDate>05200</StopDate>
<StopTime>0805</StopTime>
<CrewSize>6</CrewSize>
<CategoryOfLaborCode>1</CategoryOfLaborCode>
<ActivityIdentifierCode>02</ActivityIdentifierCode>
<CorrectedByIMDSCDBUserId>GU03CW</CorrectedByIMDSCDBUserId>
<CorrectiveActionNarrative>Test Test</CorrectiveActionNarrative>
<InspectedByIMDSCDBUserId>GU03CW</InspectedByIMDSCDBUserId>
<DocumentMoreTCTOThisJobControlNumber/>
<InspectionPassed>Y</InspectionPassed>
<BypassDateEdits/>
</EndItemTCTOReporting>
</IMDSCDB>

Desired output is:

<?xml version="1.0" encoding="UTF-8"?>
<IMDSCDB xmlns="http://xml.dod.mil/log/maint/fs/main/4.0.0">
<EndItemTCTOReporting originator="EMOC">
<PartialJobDataDocumentationData/>
<JobControlNumber>
<EventId>052790038</EventId>
<WorkcenterEvent>001</WorkcenterEvent>
</JobControlNumber>

<HomeEnterpriseLocationCode>7494</HomeEnterpriseLocationCode>
<CurrentEnterpriseLocationCode>7494</CurrentEnterpriseLocationCode>
<HostUnitDateAndTime>2006-02-23T19:29:37</HostUnitDateAndTime>
<TransactionOrdinalDate>06054</TransactionOrdinalDate>
<ComponentPosition>0</ComponentPosition>
<HowMalfunctionCode>802</HowMalfunctionCode>
<UnitsProduced>01</UnitsProduced>
<StartTime>0800</StartTime>
<StopDate>05200</StopDate>
<StopTime>0805</StopTime>
<CrewSize>6</CrewSize>
<CategoryOfLaborCode>1</CategoryOfLaborCode>
<ActivityIdentifierCode>02</ActivityIdentifierCode>
<CorrectedByIMDSCDBUserId>GU03CW</CorrectedByIMDSCDBUserId>
<CorrectiveActionNarrative>Test Test</CorrectiveActionNarrative>
<InspectedByIMDSCDBUserId>GU03CW</InspectedByIMDSCDBUserId>

<InspectionPassed>Y</InspectionPassed>
<BypassDateEdits/>
</EndItemTCTOReporting>
</IMDSCDB>

XSLT to remove all empty nodes is:

<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[not(descendant::text()[normalize-space()])]" >
</xsl:template>
</xsl:stylesheet>

I believe I need to use the | operator to select the additional node set of just the <BypassDateEdits> node, but repeated attempt and research on the web has enabled me to find a solution.

Any assistance would be appreciated.

Bill
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 26 2012
Added on Feb 23 2012
6 comments
1,561 views