473,320 Members | 2,109 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,320 software developers and data experts.

xsl syntax to generate all caps with _

Hi,

I have the following in my xml file:

<attribute name="bbBusState">

I need to generate to the following:

public static final String BB_BUS_STATE_ATTR_TYPE.

Any hints???

//Mikael

Jul 20 '05 #1
3 4450
Hi Mikael,

Try the translate() function, e.g.

<xsl:value-of
select="translate(@name,'abcdefghijklmnopqrstuvwxy z','ABCDEFGHIJKLMNOPQRSTUV
WXYZ')"/>

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Mikael Petterson" <mi*************@hotmail.com> wrote in message
news:9WK7b.3317$P51.5569@amstwist00...
Hi,

I have the following in my xml file:

<attribute name="bbBusState">

I need to generate to the following:

public static final String BB_BUS_STATE_ATTR_TYPE.

Any hints???

//Mikael

Jul 20 '05 #2
Ooops, didn't read the question properly...

Try something like...

== XML =========================================
<?xml version="1.0"?>
<root>
<attribute name="bbBusState"/>
</root>
== end of XML ==================================

== XSL =========================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="ucase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>

<xsl:template match="root">
<xsl:apply-templates select="attribute"/>
</xsl:template>

<xsl:template match="attribute">
<xsl:text>public static final String </xsl:text>
<xsl:call-template name="Camel2Underscore">
<xsl:with-param name="str" select="@name"/>
</xsl:call-template>
<xsl:text>_ATTR_TYPE</xsl:text>
</xsl:template>

<xsl:template name="Camel2Underscore">
<xsl:param name="str"/>
<xsl:param name="u-str"
select="translate($str,$ucase,'||||||||||||||||||| |||||||')"/>
<xsl:choose>
<xsl:when test="substring($u-str,1,1) = '|'">
<xsl:text>_</xsl:text>
<xsl:value-of select="substring($str,1,1)"/>
<xsl:call-template name="Camel2Underscore">
<xsl:with-param name="str" select="substring($str,2)"/>
<xsl:with-param name="u-str" select="substring($u-str,2)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($u-str,'|')">
<xsl:variable name="runlen"
select="string-length(substring-before($u-str,'|'))"/>
<xsl:value-of
select="translate(substring($str,1,$runlen),$lcase ,$ucase)"/>
<xsl:call-template name="Camel2Underscore">
<xsl:with-param name="str" select="substring($str,$runlen + 1)"/>
<xsl:with-param name="u-str" select="substring($u-str,$runlen +
1)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate($str,$lcase,$ucase)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
== end of XSL ==================================

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"Marrow" <marrow-NO-@-SPAM-marrowsoft.com> wrote in message
news:HK*******************@newsfep2-win.server.ntli.net...
Hi Mikael,

Try the translate() function, e.g.

<xsl:value-of
select="translate(@name,'abcdefghijklmnopqrstuvwxy z','ABCDEFGHIJKLMNOPQRSTUV WXYZ')"/>

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Mikael Petterson" <mi*************@hotmail.com> wrote in message
news:9WK7b.3317$P51.5569@amstwist00...
Hi,

I have the following in my xml file:

<attribute name="bbBusState">

I need to generate to the following:

public static final String BB_BUS_STATE_ATTR_TYPE.

Any hints???

//Mikael


Jul 20 '05 #3

"Mikael Petterson" <mi*************@hotmail.com> wrote in message
news:9WK7b.3317$P51.5569@amstwist00...
Hi,

I have the following in my xml file:

<attribute name="bbBusState">

I need to generate to the following:

public static final String BB_BUS_STATE_ATTR_TYPE.

Any hints???
Hi Mikael,

One can simply use the "str-map" template of FXSL as follows:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:testmap="my:testmap"
exclude-result-prefixes="xsl testmap"

<xsl:import href="str-map.xsl"/>

<xsl:variable name="vLower" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="vUpper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>

<xsl:output omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="/">
<xsl:variable name="vTestMap" select="document('')/*/testmap:*[1]"/>
<xsl:variable name="vName">
<xsl:call-template name="str-map">
<xsl:with-param name="pFun" select="$vTestMap"/>
<xsl:with-param name="pStr" select="*/@name"/>
</xsl:call-template>
</xsl:variable>

public static final String <xsl:text/>
<xsl:value-of select="$vName"/>
</xsl:template>

<testmap:testmap/>
<xsl:template match="testmap:*">
<xsl:param name="arg1"/>

<xsl:if test="contains($vUpper, $arg1)">_</xsl:if>

<xsl:value-of select="translate($arg1, $vLower, $vUpper)"/>
</xsl:template>

</xsl:stylesheet>

When this transformation is applied on your source.xml:

<attribute name="bbBusState"/>

the wanted output is produced:

public static final String BB_BUS_STATE

Hope this helped.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Jul 20 '05 #4

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
23
by: C. Barnes | last post by:
I vote for def f(): (body of function) This is backwards compatible (Python <= 2.3 raise SyntaxError), and looks much nicer than @. The only problem is that you can't one-line a...
18
by: Robert | last post by:
Hi! I was wondering if the was any way to determine the state of the caps lock key, on or off. Of course I can capture the key events and see whether the caps lock is pressed, but that does not...
26
by: GS | last post by:
I am doing my first real embedded programming project and the supplied device libraries have a function definition that looks like this: void FCN(void) = { INTDEF, INTABS, (unsigned short)...
7
by: John A Grandy | last post by:
does anyone know of an intrinsic .NET function , or font , or other mechanism , to do "proper-case all-caps" ... ? so, for a name like "Arnold Schwarzenegger" ... .... I want it entirely in...
2
by: Nikolay Petrov | last post by:
I am using Encryption/Decryption in one of my applications. This process needs a key, which should be stored somewhere. I don't want to store it in my code, so I come with idea to make a function...
1
by: charlies224 | last post by:
Hi, I am writting a software that requires me to make sure the Num Lock is always on and Caps Lock is always off. First, I know how to detect if Num Lock or Caps Lock is on or off (if...
5
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
9
by: trondhuso | last post by:
Hi, I have a solution that - at time of writing - has to use tables to render a list of database-results. My challenge though is that we have used iframes and such to render the different lists...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.