• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

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.
0
mr_stevie
Asked:
mr_stevie
  • 2
  • 2
1 Solution
 
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)
0
 
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

0
 
mr_stevieAuthor Commented:
Thanks anyway for your help anyway.
0
 
David Johnson, CD, MVPOwnerCommented:
actually it depends upon your xlst but glad to hear you solved it.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now