473,803 Members | 4,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT/xpath string functions

Hi,

I want to convert with XSLT/XPATH a String like "Aaa bbb ccc" with
variant length into to "AaaBbbCcc" .

I think it should be possible with these steps:
1) tokenize the String with ' ' as separator with tokenize()
2) make the first character uppercase with substring() and upper-case()
3) put them together with concat()

Can anybody tell me, how I glue those steps together in XSLT?

Peter
Jul 20 '05 #1
2 7272


Peter Gerstbach wrote:

I want to convert with XSLT/XPATH a String like "Aaa bbb ccc" with
variant length into to "AaaBbbCcc" .

I think it should be possible with these steps:
1) tokenize the String with ' ' as separator with tokenize()
2) make the first character uppercase with substring() and upper-case()
3) put them together with concat()

Can anybody tell me, how I glue those steps together in XSLT?


Here is my attempt with XSLT/XPath 1.0:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" encoding="UTF-8" />

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

<xsl:template name="upperCase ">
<xsl:param name="textToTra nsform" />
<xsl:variable name="head">
<xsl:choose>
<xsl:when test="contains( $textToTransfor m, ' ')">
<xsl:value-of select="substri ng-before($textToT ransform, ' ')" />
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="$textTo Transform" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="tail" select="substri ng-after($textToTr ansform, '
')" />
<xsl:variable name="firstTran sform"
select="concat( translate(subst ring($head, 1, 1),
'abcdefghijklmn opqrstuvwxyz', 'ABCDEFGHIJKLMN OPQRSTUVWXYZ'),
substring($head , 2))" />
<xsl:choose>
<xsl:when test="$tail">
<xsl:value-of select="$firstT ransform" />
<xsl:call-template name="upperCase ">
<xsl:with-param name="textToTra nsform" select="$tail" />
</xsl:call-template>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="$firstT ransform" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="text/text()">
<xsl:call-template name="upperCase ">
<xsl:with-param name="textToTra nsform" select="normali ze-space(.)" />
</xsl:call-template>
</xsl:template>

</xsl:stylesheet>

Test document

<?xml version="1.0" encoding="UTF-8"?>
<root>
<text>Aaa bbb ccc</text>
<text>xxx yyy zzzzz </text>
</root>

is transformed to

<?xml version="1.0" encoding="UTF-8"?>
<root>
<text>AaaBbbCcc </text>
<text>XxxYyyZzz zz</text>
</root>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Martin Honnen wrote:

Here is my attempt with XSLT/XPath 1.0:
...


Thanks a lot, Martin! That rocks... :)

Peter
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1705
by: Bill Sneddon | last post by:
Does anyone on this site have an informed guess as to when the standards XSLT 2.0 and XPATH 2.0 will be publish and how long it will take for the common processor will support them?
3
12651
by: Jurrie | last post by:
Hi all, Is there a function or something in XSLT or XSL-FO to make data from an XML-file uppercase? I ask this becouse I have a XML-document with <title>whatever</title> tags, and i want the data to appear in uppercase in the final PDF-document. Thanks for any help
4
21212
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a native English speaker, it's quite hard to make the problem clear. Please see the following example.
0
380
by: Jay Allard | last post by:
Hello I posted this in the vb.net group on the 2/25/2004, but didn't get any response. Here's attempt 2. Does anyone know of a more appropriate place to post this? One new piece of information: It fails on any method that it happens to hit first. I juggled the methods a bit, and it just doesn't matter. As soon as the XslTransform hits an extension function, it fails with an invalid argument exception.
5
16886
by: Per Johansson | last post by:
Is it possible to use XSLT to automatically create href links while it formats an XML document? That is, if it finds "http://me.us/" in a text, it adds <a href="http://me.us/">http://me.us/</a> -- Per Johansson Systems developer http://per.johansson.name/
1
2421
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT stylesheets, that generates .NET assemblies) 2. Performance improvements in the XslCompiledTransform
3
1825
by: requeth | last post by:
Allo, I'm a little confused. I have an XSLT, in which my parser selects a node, but I want to just capture the first two characters to a variable. How would I do this? I know how to create the variable, but I'm not sure how to take just the first two characters of the string. Thanks, RT Starid
2
22780
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values in the attribute of an element. Instead of using the <xsl:attribute> element, you can simply place the xpath in the attribute itself. The most common usage of this is in creating hyperlinks.
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.