Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 13th, 2007, 01:13 PM
Authorized User
 
Join Date: Dec 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Concat Help Needed

I am pretty knew to XSLT and any help would be appreciated in this regards.

Here is what i am looking for

I have a set of fields coming in and need to concat
1. VKORG (Value "1004")
2. PARTNER_Q = AG then PARTNER_ID (Here i have to have a condition on "AG" as string then take the ID field) (Value "52791399")
3. Constant as "SN" value (Value "SN")
4. SPART field (Value "09")
5. Two Spaces as constant (Value " ")
6. VTWEG (Value "12")
The output string should look like

"100452791399SN09 12"

Any gurus can write small script for me?

 
Old December 13th, 2007, 01:17 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

And what have you tried so far? Lets see you XSLT..

/- Sam Judson : Wrox Technical Editor -/
 
Old December 13th, 2007, 01:20 PM
Authorized User
 
Join Date: Dec 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not sure on how to have IF condition for PARTNER_Q='AG' to check value and pass ID value to the concat

<xsl:value-of select="concat(VKORG,PARTNER_ID,'SN','SPART'," ",VTWEG)"/>

 
Old December 13th, 2007, 01:26 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Are you using XSLT 2.0?
It has an
  
Code:
if (condition) then exp1 else exp2

expression that could help in your case:

  
Code:
<xsl:value-of select="concat(VKORG,if (PARTNER_Q = 'AG') then PARTNER_ID else '','SN','SPART',"  ",VTWEG)"/>


 
Old December 13th, 2007, 01:41 PM
Authorized User
 
Join Date: Dec 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wow u made my day. it's working.

I am such a dumbo, shame on myself. Thanks for your help, Appreciated

 
Old August 5th, 2010, 12:51 AM
Authorized User
 
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow Recursive Concatenation

I know this question must have been answered before but cannot locate it.

I want to create a recursive function (I assume) that will take a string and simply add a character (e.g. #) after each letter.

For example:
HELLO --> H#E#L#L#O

Started doing this and am not getting desired result:
<xsl:template name="addCharToString">

<xsl:param name="myString" />
<xsl:param name="stringRem"/>
<xsl:param name="charToAdd" select="'#'" />

<xsl:variable name="firstChar" select="substring($myString,1,1)" />

<xsl:choose>
<xsl:when test="string-length($stringRem) &gt; 1">

<xsl:variable name="newString" select="concat($firstChar, $charToAdd)" />

<xsl:call-template name="addCharToString">
<xsl:with-param name="myString" select="substring($stringRem, 2, string-length($myString)) " />
</xsl:call-template>

</xsl:when>

<xsl:otherwise>
<xsl:value-of select="$newString" />

</xsl:otherwise>

</xsl:choose>

</xsl:template>
Call:
<xsl:call-template name="addCharToString">
<xsl:with-param name="myString" select="'HELLO'" />
<xsl:with-param name="remString" select="'HELLO'" />
</xsl:call-template>

Was trying to follow another example for Capitalizing, but it's not the same animal.
 
Old August 5th, 2010, 02:00 AM
Authorized User
 
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Follow-up:
I came up with this, which seems to work:
<xsl:template name="addCharToString">

<xsl:param name="myString" />
<xsl:param name="charToAdd" select="'#'" />

<xsl:variable name="firstChar" select="substring($myString,1,1)" />

<xsl:choose>
<xsl:when test="string-length($myString) &lt;= 1">
<xsl:value-of select="$myString"/>
</xsl:when>

<xsl:otherwise>
<xsl:variable name="newString">
<xsl:call-template name="addCharToString">
<xsl:with-param name="myString" select="substring($myString, 2, string-length($myString)) " />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat($firstChar, $charToAdd, $newString)" />
</xsl:otherwise>
</xsl:choose>

</xsl:template>

Call:
<xsl:call-template name="addCharToString">
<xsl:with-param name="myString" select="'HELLO" />
</xsl:call-template>

I guess this is a reasonable approach?

Thanks.
Robert





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to do Very Large String Concat? EcceBozo XSLT 2 July 29th, 2008 03:58 PM
String.Concat NOT same as '&" Ron Howerton Visual Basic 2005 Basics 0 November 21st, 2006 04:34 PM
concat 2 different cursor sreekesh ADO.NET 0 August 18th, 2006 07:11 AM
concat function help! migake XSLT 2 May 2nd, 2006 09:31 AM
concat problems gonesail XSLT 1 May 12th, 2004 08:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.