Joining strings/variables in XSLT/Xpath

Hello EE,

I've been looking everywhere but I can't seem to find an answer (maybe I'm not looking hard enough... :()

Anyways, I have an XML document of addresses that I import and extract the variables like the following:

<xsl:variable name="StreetNo" select="Address/StreetNo"/> 
<xsl:variable name="Street" select="Address/Street"/> 
<xsl:variable name="Suburb" select="Address/Suburb"/> 
<xsl:variable name="State" select="Address/State"/> 
<xsl:variable name="Postcode" select="Address/Postcode"/>

Open in new window


I have to join all the variables into one string into a new variable "NewAddress" like the following:

<xsl:variable name="NewAddress" select="$StreetNo + ' ' + $Street + ' ' + $Suburb + ', ' + $State + ' ' + $Postcode"/>

Open in new window


I want it so it'll print a string like "123 Smith Street Sydney, New South Wales 2000".

I'm not getting the right output and it's returning as "NaN". I'm pretty sure the "+" only works with numbers and using a "." doesn't seem to work either.

Hope this makes sense. Can anyone help me with this?

Thank you very much in advance.
LVL 1
mr_stevieAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
declare everything as a string vice number even address/streetno otherwise you are mixing types and getting the NaN (Not a Number)
mr_stevieAuthor Commented:
Apparently all XML elements passed through to XSL will be string regardless of what kind of data is in each field.

The reason I've been getting NaN is because "+" is an operator used with numerical data and strings can not be added since they're not numeric.

Anyways, I managed to do what I wanted with the following:

 
<xsl:variable name="StreetNo" select="Address/StreetNo"/> 
<xsl:variable name="Street" select="Address/Street"/> 
<xsl:variable name="Suburb" select="Address/Suburb"/> 
<xsl:variable name="State" select="Address/State"/> 
<xsl:variable name="Postcode" select="Address/Postcode"/>
<xsl:variable name="Space" select="' '"/>
<xsl:variable name="Comma" select="', '"/>

<xsl:variable name="NewAddress" select='concat($StreetNo, $Space, $Street, $Comma, $Suburb, $Comma, $State, $Space, $Postcode, $Comma)'/>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mr_stevieAuthor Commented:
Thanks anyway for your help anyway.
David Johnson, CD, MVPOwnerCommented:
actually it depends upon your xlst but glad to hear you solved it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.