Problem to remove underscore in template

Discussion in 'XML' started by Mikael Petterson, Sep 20, 2003.

  1. 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:eek:therwise>
    <xsl:value-of select="translate($str,$lcase,$ucase)"/>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:template>
    </xsl:stylesheet>
     
    Mikael Petterson, Sep 20, 2003
    #1
    1. Advertising

  2. 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" <> 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:eek:therwise>
    > <xsl:value-of select="translate($str,$lcase,$ucase)"/>
    > </xsl:eek:therwise>
    > </xsl:choose>
    > </xsl:template>
    > </xsl:stylesheet>
    >
     
    Dimitre Novatchev, Sep 20, 2003
    #2
    1. Advertising

  3. 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" <> 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:eek:therwise>
    >> <xsl:value-of select="translate($str,$lcase,$ucase)"/>
    >> </xsl:eek:therwise>
    >> </xsl:choose>
    >></xsl:template>
    >></xsl:stylesheet>
    >>

    >
    >
     
    Mikael Petterson, Sep 20, 2003
    #3
  4. "Mikael Petterson" <> 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
     
    Dimitre Novatchev, Sep 20, 2003
    #4
  5. 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" <> 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
    >
    >
     
    Mikael Petterson, Sep 20, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antonio
    Replies:
    2
    Views:
    429
    tdavisjr
    Nov 4, 2005
  2. Kerry Kimbrough
    Replies:
    6
    Views:
    14,888
    Chris Smith
    Feb 27, 2004
  3. ABC
    Replies:
    1
    Views:
    2,015
    Kevin Spencer
    Apr 22, 2006
  4. Kanon
    Replies:
    1
    Views:
    454
    Florent Georges
    Dec 26, 2005
  5. =?Utf-8?B?Q2hhcmxpZQ==?=

    Nunit Asp.Net - control name contains underscore problem

    =?Utf-8?B?Q2hhcmxpZQ==?=, Aug 24, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    471
    =?Utf-8?B?Q2hhcmxpZQ==?=
    Aug 24, 2006
Loading...

Share This Page