Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8165893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:40:43+00:00 2026-06-06T19:40:43+00:00

I have an XML workflow where we’re building an output document from an XML

  • 0

I have an XML workflow where we’re building an output document from an XML source but some of the data elements are empty but still appearing in the output. The problem is that we are generating paragraph returns and spacing based on the final output.

In some cases the data contains <address1> and <address2> elements. When it does we want it to look like this (A):

<address1>123 Main Str</address1><xsl:text> </xsl:text><zip>60060</zip>

When does not have data in the <address2> element, we want it to appear this way (B):

<address1>123 Main Str</address1> <hours>M-F 9:00am - 5:00pm</hours><xsl:text> 
</xsl:text><address2>PO Box 123</address2> <zip>60060</zip>

BUT, the XML contains EMPTY data elements such as <address2></address2> so we end up with the following situation (C):

<address1>123 Main Str</address1> <hours>M-F 9:00am - 5:00pm</hours><xsl:text> 
</xsl:text><address2/><xsl:text> </xsl:text><zip>60060</zip>

Our XSL works fine until it hits an empty element. I’m sure there’s a way to create option A even when there is an empty element. I tried using <xsl:if test="string-length(node) != 0"> but I couldn’t get it to work. I want to get rid of the empty <address2/> elements and move the <zip> element up to the previous line.

Here is my current XSL:

<?xml version="1.0" encoding="UTF-8"?><!-- DWXMLSource="IndividualBanks_2011 final.xml" -->
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>

<xsl:output method="xml"/>
<xsl:template match="/">

<Root>
<Story><xsl:apply-templates select="Root"/></Story>
</Root>
</xsl:template>

<xsl:template match="BankName | Address1 | Hours | Established | RoutingNbr | CO/CityOfficePhone | CO/CityOfficeAddress2 "><xsl:element name="{name()}"><xsl:value-of select="."/></xsl:element></xsl:template>
<xsl:template match="BK">
<xsl:apply-templates select="BankName"/><xsl:text>  </xsl:text><xsl:apply-templates select="Established"/>    <xsl:text>    </xsl:text><xsl:apply-templates select="RoutingNbr"/><xsl:text>
</xsl:text>
<xsl:apply-templates select="OfficeOfLabel"/>
<xsl:apply-templates select="Address1"/><xsl:text>  </xsl:text><xsl:apply-templates select="Hours"/>
<xsl:apply-templates select="Address2"/><xsl:apply-templates select="Zip"/>
</xsl:template>
<xsl:template match="Address2"><xsl:text>
</xsl:text><Address2><xsl:value-of select="."/></Address2><xsl:text>    </xsl:text>
</xsl:template>

<xsl:template match="Zip">
<Zip><xsl:value-of select="."/></Zip><xsl:text>
</xsl:text></xsl:template>
</xsl:stylesheet>

Here is the XML data source:

<Root><BK><BankName>Ames National Corporation</BankName><Established>Est. 1975</Established><RoutingNbr>8020-0135-0</RoutingNbr><Address1>405 5th Street</Address1><Hours>Hrs: M-F 8-5</Hours><Address2></Address2>  <Zip>50010</Zip><Fax>FAX: (515) 663-3033</Fax><Phone>(515) 232-6251</Phone><WebURL>Web: www.amesnational.com</WebURL><MultiBankLabel>Please see Multi-Bank Holding Companies section</MultiBankLabel>
</BK>
<BK><BankName>Bank of the West</BankName><Address1>525 Main</Address1><Zip>50010-6008</Zip><Fax>FAX: (515) 232-3791</Fax><Phone>(515) 232-8664</Phone><OfficeOfLabel>Office of Bank of the West, West Des Moines</OfficeOfLabel>
<EH><Employee>Michael Sondall, BM</Employee></EH>
</BK>
<BK><BankName>Bankers Trust Company</BankName><Address1>1510 Buckeye </Address1><Zip>50010</Zip><Phone>(515) 233-4424</Phone><WebURL>Web: www.bankerstrust.com</WebURL><OfficeOfLabel>Office of Bankers Trust Company, Des Moines</OfficeOfLabel>
<EH><Employee>John Russell, VP</Employee></EH>
</BK>
<BK><BankName>Exchange State Bank</BankName><RoutingNbr>0739-0950-7</RoutingNbr><Address1>823 Wheeler, Ste 32</Address1><Zip>50010</Zip><Fax>FAX: (515) 232-5068</Fax><Phone>(515) 232-5060</Phone><Email>e-Mail: ames@esb1.com</Email><OfficeOfLabel>Office of Exchange State Bank, Collins</OfficeOfLabel>
<EH><Employee>Allison Appel, VP, CPA</Employee></EH><EH><Employee>Christine Heintz, AVP</Employee></EH>
</BK>
<BK><BankName>First American Bank</BankName><Established>Est. 1956</Established><RoutingNbr>0739-0080-7</RoutingNbr><Address1>1530 S Duff Avenue, Ste 1</Address1><Hours>Hrs: M-TH 9-5 SAT 8-12</Hours><Address2>    </Address2><Zip>50010</Zip><Fax>FAX: (515) 956-3160</Fax><Phone>(515) 233-2033</Phone><WebURL>Web: </WebURL>    <OfficeOfLabel>Office of First American Bank, Fort Dodge</OfficeOfLabel>
<EH><Employee>Steve Goodhue, Reg Pres</Employee></EH>
</BK></Root>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:40:45+00:00Added an answer on June 6, 2026 at 7:40 pm

    Your approach with the string-length function wasn’t bad, but maybe you inserted it in the wrong place?

    The <Zip> element is on the previous line for me when I replace your XSLT line

    <xsl:template match="Address2"><xsl:text>
    

    with

    <xsl:template match="Address2[string-length() != 0]"><xsl:text>
    

    Does that do what you want? I’m not quite sure whether you also want to skip the <Hours> if there’s no <Address2> specified.

    Update: In order to apply a different ordering to the elements if <Address2> is empty, use an <xsl:choose> structure with a similar condition as above:

    <xsl:template match="BK">
    <xsl:apply-templates select="BankName"/><xsl:text>  </xsl:text><xsl:apply-templates select="Established"/>    <xsl:text>    </xsl:text><xsl:apply-templates select="RoutingNbr"/><xsl:text>
    </xsl:text>
    <xsl:apply-templates select="OfficeOfLabel"/>
    <xsl:choose>
    <xsl:when test="string-length(Address2) != 0">
    <xsl:apply-templates select="Address1"/><xsl:text>  </xsl:text><xsl:apply-templates select="Hours"/>
    <xsl:apply-templates select="Address2"/><xsl:apply-templates select="Zip"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:apply-templates select="Address1"/><xsl:text>   </xsl:text><xsl:apply-templates select="Zip"/><xsl:text>  </xsl:text><xsl:apply-templates select="Hours"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>
    

    You can then completely skip the template for <Address2>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some xml, I want to give it to a List dataprovider, but
I have XML tag that has the content which is HTML document. <xml-tag> <!--
Let's suppose I have xml like this one: <Server Active=No> <Url>http://some.url</Url> </Server> C# class
I have a workflow where I need to render an exception page. But this
i have this XSLT and XML payload that i am wanting to transform. but
I have this xml file and I want to get some values with Xpath.
I have a variable in javascript containing a string of XML data that I
I have an XML like this (a workflow represents a sort of a class
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.