By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,719 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,719 IT Pros & Developers. It's quick & easy.

Problem to remove underscore in template

P: n/a
Hi,

I got some help to go from:

bbBusState to BB_BUS_STATE.

However I found out :-( that the xml contained attributes like:

TxDeviceGroup and that becomes:

_TX_DEVICE_GROUP
This is the code I got from Marrow (thanks Marrow :-)) (See below)
I must admit (Marrow) that I do not fully understand what the code
does so I am having problems to modify it to remove the underscore
for attributes that begins with a cap.

I have tried to add the following code (see My code below).

My strings became a mess :-(

//Mikael

My code
=======
<xsl:choose>
<xsl:when test="starts-with($u-str,'|')">
<xsl:variable name="u-str-len" select="string-length($u-str)"/>
<xsl:variable name="u-str-rest" select="substring($u-str,2,$u-str-len)"/>
<xsl:variable name="str-first-chr" select="substring($str,1,1)"/>
<xsl:call-template name="Camel2Underscore">
<xsl:with-param name="u-str" select="concat($str-first-chr,
$u-str-rest)"/>
</xsl:call-template>
</xsl:when>

================================================== =====

<xsl:template name="Camel2Underscore">
<xsl:param name="str"/>
<xsl:param name="u-str"
select="translate($str,$ucase,'||||||||||||||||||| |||||||')"/>

<!-- Here I tested to add my code -->

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

Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Without having to know the code that you were using, there are simple ways
to remove the leading underscore:

1.
<xsl:variable name="vresult1">
<xsl:call-template name="capitalize">
<xsl:with-param name="str" select="$someStr"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="theResult" select="substring($vresult1, 1 +
contains($allCaps, substring($someStr, 1, 1)))"/>

2.
<xsl:variable name="vresult1">
<xsl:call-template name="capitalize">
<xsl:with-param name="str" select="substring($someStr, 2)"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="theResult" select="concat(translate(substring($someStr,
1, 1), $lowercase, $allCaps), $vresult1)"/>
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Mikael Petterson" <mi*************@hotmail.com> wrote in message
news:Ia_ab.5421$P51.8313@amstwist00...
Hi,

I got some help to go from:

bbBusState to BB_BUS_STATE.

However I found out :-( that the xml contained attributes like:

TxDeviceGroup and that becomes:

_TX_DEVICE_GROUP
This is the code I got from Marrow (thanks Marrow :-)) (See below)
I must admit (Marrow) that I do not fully understand what the code
does so I am having problems to modify it to remove the underscore
for attributes that begins with a cap.

I have tried to add the following code (see My code below).

My strings became a mess :-(

//Mikael

My code
=======
<xsl:choose>
<xsl:when test="starts-with($u-str,'|')">
<xsl:variable name="u-str-len" select="string-length($u-str)"/>
<xsl:variable name="u-str-rest" select="substring($u-str,2,$u-str-len)"/> <xsl:variable name="str-first-chr" select="substring($str,1,1)"/>
<xsl:call-template name="Camel2Underscore">
<xsl:with-param name="u-str" select="concat($str-first-chr,
$u-str-rest)"/>
</xsl:call-template>
</xsl:when>

================================================== =====

<xsl:template name="Camel2Underscore">
<xsl:param name="str"/>
<xsl:param name="u-str"
select="translate($str,$ucase,'||||||||||||||||||| |||||||')"/>

<!-- Here I tested to add my code -->

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

Jul 20 '05 #2

P: n/a
Hmmmmmmm.... Simple for you yeah. Not for me.

You first define a variable called vresult1 then you call a
template called capitalize. And you send, I assume _TR_DEVICE_GROUP to
that template. Then you define a variable that is called theResult. I
guess this is where we get the TR_DEVICE_GROUP output. Which part do I
need to implement?
//Mikael

Dimitre Novatchev wrote:
Without having to know the code that you were using, there are simple ways
to remove the leading underscore:

1.
<xsl:variable name="vresult1">
<xsl:call-template name="capitalize">
<xsl:with-param name="str" select="$someStr"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="theResult" select="substring($vresult1, 1 +
contains($allCaps, substring($someStr, 1, 1)))"/>

2.
<xsl:variable name="vresult1">
<xsl:call-template name="capitalize">
<xsl:with-param name="str" select="substring($someStr, 2)"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="theResult" select="concat(translate(substring($someStr,
1, 1), $lowercase, $allCaps), $vresult1)"/>
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Mikael Petterson" <mi*************@hotmail.com> wrote in message
news:Ia_ab.5421$P51.8313@amstwist00...
Hi,

I got some help to go from:

bbBusState to BB_BUS_STATE.

However I found out :-( that the xml contained attributes like:

TxDeviceGroup and that becomes:

_TX_DEVICE_GROUP
This is the code I got from Marrow (thanks Marrow :-)) (See below)
I must admit (Marrow) that I do not fully understand what the code
does so I am having problems to modify it to remove the underscore
for attributes that begins with a cap.

I have tried to add the following code (see My code below).

My strings became a mess :-(

//Mikael

My code
=======
<xsl:choose>
<xsl:when test="starts-with($u-str,'|')">
<xsl:variable name="u-str-len" select="string-length($u-str)"/>
<xsl:variable name="u-str-rest"


select="substring($u-str,2,$u-str-len)"/>
<xsl:variable name="str-first-chr" select="substring($str,1,1)"/>
<xsl:call-template name="Camel2Underscore">
<xsl:with-param name="u-str" select="concat($str-first-chr,
$u-str-rest)"/>
</xsl:call-template>
</xsl:when>

================================================ =======

<xsl:template name="Camel2Underscore">
<xsl:param name="str"/>
<xsl:param name="u-str"
select="translate($str,$ucase,'||||||||||||||||| |||||||||')"/>

<!-- Here I tested to add my code -->

<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),$lca se,$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>



Jul 20 '05 #3

P: n/a

"Mikael Petterson" <mi*************@hotmail.com> wrote in message
news:KJ%ab.5445$P51.8312@amstwist00...
Hmmmmmmm.... Simple for you yeah. Not for me.

You first define a variable called vresult1 then you call a
template called capitalize. And you send, I assume _TR_DEVICE_GROUP to
that template.
No. I pass to it "TrDeviceGroup"

As result the value of $vresult1 will be _TR_DEVICE_GROUP

The "capitalize" template is all you had at the moment (regardless if it
were Marrow's solution, or the FXSL-based solution I proposed).
Then you define a variable that is called theResult. I
guess this is where we get the TR_DEVICE_GROUP output.
Yes.
Which part do I
need to implement?


Absolutely nothing to implement -- just define the variables in this way.
=====
Cheers,

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

P: n/a
Hi,

Thanks for the explanation. It really helped me out. You saved me since
I needed to write a code generator and discovered some inconsistencies.

Thanks again!! Have a nice evening!

//Mikael

Dimitre Novatchev wrote:
"Mikael Petterson" <mi*************@hotmail.com> wrote in message
news:KJ%ab.5445$P51.8312@amstwist00...
Hmmmmmmm.... Simple for you yeah. Not for me.

You first define a variable called vresult1 then you call a
template called capitalize. And you send, I assume _TR_DEVICE_GROUP to
that template.

No. I pass to it "TrDeviceGroup"

As result the value of $vresult1 will be _TR_DEVICE_GROUP

The "capitalize" template is all you had at the moment (regardless if it
were Marrow's solution, or the FXSL-based solution I proposed).

Then you define a variable that is called theResult. I
guess this is where we get the TR_DEVICE_GROUP output.

Yes.

Which part do I
need to implement?

Absolutely nothing to implement -- just define the variables in this way.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.