 |
| 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
|
|
|
|

December 13th, 2007, 01:13 PM
|
|
Authorized User
|
|
Join Date: Dec 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

December 13th, 2007, 01:17 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
And what have you tried so far? Lets see you XSLT..
/- Sam Judson : Wrox Technical Editor -/
|
|

December 13th, 2007, 01:20 PM
|
|
Authorized User
|
|
Join Date: Dec 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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)"/>
|
|

December 13th, 2007, 01:26 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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)"/>
|
|

December 13th, 2007, 01:41 PM
|
|
Authorized User
|
|
Join Date: Dec 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Wow u made my day. it's working.
I am such a dumbo, shame on myself. Thanks for your help, Appreciated
|
|

August 5th, 2010, 12:51 AM
|
|
Authorized User
|
|
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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) > 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.
|
|

August 5th, 2010, 02:00 AM
|
|
Authorized User
|
|
Join Date: May 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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) <= 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
|
|
 |