'Select' 2 pieces of info (XSLT file)

144 views Asked by At

I am trying to link our Magento website with Sage 50 with a piece of software.

We would like the customers first name and last name to go into the company field.

Below are the 3 lines I assume I have to tweak:

   <Forename><xsl:value-of select="billing_address/firstname"/></Forename>
    <Surname><xsl:value-of select="billing_address/lastname"/></Surname>
    <Company><xsl:value-of select="billing_address/company"/></Company>

How do I combine first name and last name in 1 line? looking for something like:

    <Company><xsl:value-of select="billing_address/firstname, billing_address/lastname"/></Company>
3

There are 3 answers

0
Florent Georges On BEST ANSWER

First of all, whitespace-only text nodes are ignored by the XSLT engine, so what you tried above can be rewritten like the following:

<Company>
   <xsl:value-of select="billing_address/firstname, billing_address/lastname"/>
</Company>

Second, you have to understand that xsl:value-of generates a text node. The following will generate 2 text nodes, with resp. the first and last names:

<Company>
   <xsl:value-of select="billing_address/firstname"/>
   <xsl:value-of select="billing_address/lastname"/>
</Company>

Then if I understand correctly, you want to seperate both with the string ", ". You can use xsl:text to generate a fixed-content text node:

<Company>
   <xsl:value-of select="billing_address/firstname"/>
   <xsl:text>, </xsl:text>
   <xsl:value-of select="billing_address/lastname"/>
</Company>

In the above, you can put the ", " directly between both value-of, but then you can't control the indentation. Usuaully, when I generate fixed text, I always use xsl:text.

0
leu On

You can give

    <Company><xsl:value-of select="concat(billing_address/firstname,', ', billing_address/lastname)"/></Company>

a try...

0
Michael Kay On

You really need to tell us which version of XSLT you are using. Your proposed code

<xsl:value-of select="billing_address/firstname, billing_address/lastname"/>

is fine in 2.0, and you can get the comma by adding the attribute separator=", "/>. But this won't work in 1.0, where xsl:value-of will only output the first item if you give it a sequence.