473,387 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 7165


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:stylesheet
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="textToTransform" />
<xsl:variable name="head">
<xsl:choose>
<xsl:when test="contains($textToTransform, ' ')">
<xsl:value-of select="substring-before($textToTransform, ' ')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$textToTransform" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="tail" select="substring-after($textToTransform, '
')" />
<xsl:variable name="firstTransform"
select="concat(translate(substring($head, 1, 1),
'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
substring($head, 2))" />
<xsl:choose>
<xsl:when test="$tail">
<xsl:value-of select="$firstTransform" />
<xsl:call-template name="upperCase">
<xsl:with-param name="textToTransform" select="$tail" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$firstTransform" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="text/text()">
<xsl:call-template name="upperCase">
<xsl:with-param name="textToTransform" select="normalize-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>XxxYyyZzzzz</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
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
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...
4
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...
0
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...
5
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> --...
1
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...
3
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.