Xslt Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bhavs
    New Member
    • Sep 2008
    • 16

    Xslt Help

    How to convert a node value to lowercase???
    I have
    <xsl:when test="//@locationName ='xyz'">

    I have to convert the locationName to lowercase in the xslt page.
    Can I use the toLower function?

    I am new to XSLT, Pls help...
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    Yes you can use toLower. Do you know how to get the value you need to change the case for?

    /MK

    Comment

    • Bhavs
      New Member
      • Sep 2008
      • 16

      #3
      Originally posted by MarkoKlacar
      Hi,

      Yes you can use toLower. Do you know how to get the value you need to change the case for?

      /MK
      Hi Mark,

      Thanks for replying.

      No, I dont know how to get value.. Can u pls let me know how to get?

      Comment

      • MarkoKlacar
        Recognized Expert Contributor
        • Aug 2007
        • 296

        #4
        Hi,

        It's Marko, but it's ok.... : - )

        In your case, if I understood in correctly, you want to get the value of an attribute? This will help you to understand how you should do that.

        Sooner or later you will probably want to get the value of an element, this is what you would want to read in order to see how that's done.

        Let me know if you need more help.

        /MK

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          Xslt Help

          Originally posted by Bhavs
          No, I dont know how to get value.. Can u pls let me know how to get?
          I think, in this case it is better to use a template or for-each construct than <xsl:if>, since you do not have access to the node-set of your test clause.

          In addition I would also recommend a xslt tutorial (e.g. w3schools.com) for reading on the template construct.

          you can apply kind-of if-statements by using a "conditiona l xpath" (like //element[@attr = 'value'])

          regards
          Last edited by Dormilich; Sep 22 '08, 10:32 AM. Reason: slightly too late in posting

          Comment

          • Bhavs
            New Member
            • Sep 2008
            • 16

            #6
            Hi Marko,
            Thanks for the info.

            Tried with the following code

            <xsl:variable name='location' >
            <xsl:call-template name='str:to-lower'>
            <xsl:with-param name='text' select='//@locationName'/>
            </xsl:call-template>
            </xsl:variable>


            But it says the the prefix 'str' is note defined

            Regards,
            Bh

            Comment

            • MarkoKlacar
              Recognized Expert Contributor
              • Aug 2007
              • 296

              #7
              Hi,

              Have you declared it? The way your code looks now you have declared a function, no need to do that since the toLower is a standard function. Perhaps you need to have a quick look at namespaces in XSL to get you started. You can also have a look at this.

              /MK

              Comment

              • Bhavs
                New Member
                • Sep 2008
                • 16

                #8
                Hi,

                I am using this namespace

                <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

                Do I need to add anything else??

                Thnks..

                Comment

                • MarkoKlacar
                  Recognized Expert Contributor
                  • Aug 2007
                  • 296

                  #9
                  Hi,

                  That should about cover it as far as I know...

                  Have you figured out how to call the function?
                  Have you solved the problem?

                  /MK

                  Comment

                  • Bhavs
                    New Member
                    • Sep 2008
                    • 16

                    #10
                    Originally posted by MarkoKlacar
                    Hi,

                    That should about cover it as far as I know...

                    Have you figured out how to call the function?
                    Have you solved the problem?

                    /MK

                    Hi Marko,

                    NO, I haven't, as I am getting an eror telling that prefix str is not defined.

                    Regards,
                    Bh

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #11
                      Xslt Help

                      As far as I know, there is no toupper-function in either XSLT 1.0 or XPath 1.0 (there you could use the translate() function, but that's not that elegant). There is such a function in XPath 2.0 (lower-case()).

                      str:to-lower is a library (XSLT Standard Library ) dependant function (this has nothing to do with the core XSLT)

                      regards

                      Comment

                      • Bhavs
                        New Member
                        • Sep 2008
                        • 16

                        #12
                        Hi all,

                        I am using XSLT 1.0

                        So, that might be the reson that str:to-lower is not getting recognised.

                        So, now I am trying to use the translate function to do the same.
                        But it doesn' seem to be working.

                        <xsl:variable name='location' >
                        <xsl:value-of select='transla te("//@locationName", "JERSEY","jerse y")'/>
                        </xsl:variable>

                        <xsl:choose>
                        <xsl:when test="location ='jersey'">
                        .
                        .
                        .
                        .
                        .
                        </xsl:choose>

                        Comment

                        • Dormilich
                          Recognized Expert Expert
                          • Aug 2008
                          • 8694

                          #13
                          Xslt Help

                          your test condition looks for a child element named location, whose string value is "jersey", if you want to use the variable, use $location.

                          btw. to put a a value in $location you should rather use the select attribute:
                          [CODE=xslt]<xsl:variable name='location' select='transla te("//@locationName", "JERSEY","jerse y")'/>
                          ...
                          <xsl:when test="$location = 'jersey'">[/CODE]
                          regards

                          Comment

                          • Bhavs
                            New Member
                            • Sep 2008
                            • 16

                            #14
                            Originally posted by Dormilich
                            your test condition looks for a child element named location, whose string value is "jersey", if you want to use the variable, use $location.

                            btw. to put a a value in $location you should rather use the select attribute:
                            [CODE=xslt]<xsl:variable name='location' select='transla te("//@locationName", "JERSEY","jerse y")'/>
                            ...
                            <xsl:when test="$location = 'jersey'">[/CODE]
                            regards
                            Hi..
                            ]<xsl:variable name='location' select='transla te("//@locationName", "JERSEY","jerse y")'/>

                            For the above, the xsl is taking //@locationName as //@locationName literally.
                            I mean its not taking the value of the node :D

                            So its translating //@locationName with //@locationname


                            Pls give me some ideas to take the value os the node here.
                            I tried many things, but none of them seem to wrk..

                            Comment

                            • Dormilich
                              Recognized Expert Expert
                              • Aug 2008
                              • 8694

                              #15
                              ah, ok.
                              you give the location path as a string (my fault, didn't see it in the first place)... try
                              [CODE=xsl]<xsl:variable name='text' select='transla te(//@locationName," JERSEY","jersey ")'/>
                              // or
                              <xsl:variable name='location' select="//@locationName"/>
                              <xsl:variable name='text' select='transla te($location,"J ERSEY","jersey" )'/>
                              ...
                              <xsl:when test="$text = 'jersey'">[/CODE]
                              regards

                              Comment

                              Working...