how to drop empty or blank fields

lets say i have an xml document called doc1, like so -

abc

next, i map doc1 to doc2.

abc

now, i wish to drop all empty or blank fields from doc2.
this would be my final intended result -

abc

what is the best way to achieve this ?

i should add that i have set string1 and string2 as Required=False and Allow Null=True.

i used XSLT to read XML and drop all empty / null fields.

I would map only when not null. That way, the tag would not get generated in the first place

i could also use a regex to remove all instances of empty strings.
but would this have a performance hit for large strings ?

sootienann,

I would stay away from doing regex and pulling out empty tags, post facto.

If you do a null check before mapping, you wouldnt have to pull the empty tags out later.

  • Hara

There is a service removeNullFields in the PSUtilites package, use that to remove the null fields from a doc.

Make sure you make a local copy of this service and include it in your test plan before you start using it, as the use of the PSUtilites services directly in prod is not recommended.

Cheers,
Akshith

hi dear sootienann …the easy way is that after getting result field with null fields again get map step for the flow and just drop null fields in pipeline output field .thanking you …

Drop null won’t pull out strings with empty values will it? ex: “ ” is what I would consider an ‘empty’ string.
When I tried using a $null branch it would remove cases such as
this → "
but not → “ ”
In which case I ended up using a regex pattern to remove all strings with values \r\n\t\s (return, newline, tab, space). Does the flow service removeNullFields in PSUtilities handle both cases above?

removeNullFields is a Java service in the PSUtilities and yes it will handle the white spaces in the input string. Make sure you set the trimFields to true, this will remove the spaces.

Cheers,
Akshith

can XSLT be used if i want to drop only optional fields which are empty?
because if i drop all empty fields, then validation will fail if mandatory fields are not present.

ideally, i am looking for a single function to drop all fields which :

  1. have the attribute Required=False
  2. are empty

Okay, that will make things easier from here on. Thanks for the info.

Marcus

can XSLT be used if i want to drop only optional fields which are empty?
because if i drop all empty fields, then validation will fail if mandatory fields are not present.

ideally, i am looking for a single function to drop all fields which :

  1. have the attribute Required=False
  2. are empty

Try below xslt. It will remove all null fields from schema.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output omit-xml-declaration="yes" indent="yes"/>
	<xsl:strip-space elements="*"/>
	<xsl:template match="node()|@*">
		<xsl:copy>
			<xsl:apply-templates select="node()|@*"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="*[not(descendant::text()[normalize-space()])]"/>
</xsl:stylesheet>

removeNullFields.xslt (428 Bytes)