<xsl:when test=""> help with xslt

Discussion in 'XML' started by Rupa, Jan 7, 2004.

  1. Rupa

    Rupa Guest

    Hi,

    I'm trying to write an xslt to convert an email in xml format to a new
    xml format.

    <descr>
    <xsl:choose> <xsl:value-of select="body"> </xsl:value-of select>
    <xsl:when test=" <xsl:value-of select="body/size_in_chars"> >
    1042"></xsl:when>
    <xsl:eek:therwise> SOMETHING HERE THAT I HAVEN'T SORTED OUT YET
    </xsl:eek:therwise>
    </xsl:choose>
    </descr>

    My first problem is the test condition. I need to check whether the
    size of the body of the email is less than 1024. In the original xml
    document, it looks like this:
    <body size_in_chars="someNumber"> body of email is here </body>

    Is there a way for me to access the size_in_chars element and use it
    in my test?

    My second problem is that if the body is greater than 1024, I need to
    truncate the body after that and select only the first 1024 characters
    for <descr>. Something like this:

    <descr> <xsl:value-of select=truncate("body", 1024)> </xsl:value-of>
    </descr>

    (I'm just using truncate() as a way to show what I need to do - don't
    know if there actually is a function to do that and what it would be
    called if it exists.)

    Thanks!
    Rupa
     
    Rupa, Jan 7, 2004
    #1
    1. Advertising

  2. In article <>,
    Rupa <> wrote:

    % <descr>
    % <xsl:choose> <xsl:value-of select="body"> </xsl:value-of select>

    This value-of is out of place and not well-formed.

    % <xsl:when test=" <xsl:value-of select="body/size_in_chars"> >
    % 1042"></xsl:when>

    The value of the test attribute is an XPath expression. You don't
    use value-of, you just use the expression directly:

    <xsl:when test="body/@size_in_chars > 1042"></xsl:when>

    Note the use of @ to get at the attributes axis. The path here is
    relative to the current node at the time the xsl:choose is evaluated.
    You could use an absolute path (perhaps /body/@size_in_chars), or
    a different relative path, depending on what the current node is.

    % My second problem is that if the body is greater than 1024, I need to
    % truncate the body after that and select only the first 1024 characters
    % for <descr>. Something like this:

    % <descr> <xsl:value-of select=truncate("body", 1024)> </xsl:value-of>
    % </descr>

    You might want to read an introduction to XPath and XSLT. The XPath
    spec is fairly readable.


    <xsl:when test="body/@size_in_chars > 1042">
    <xsl:value-of select='substr(body, 1, 1024)'/>
    </xsl:when>

    Again, `body' is a relative path and so this won't work if the current
    node isn't right.

    If all you want to do is truncate if necessary, you could do away with
    the xsl:choose and simply use substr() on everything.
    --

    Patrick TJ McPhee
    East York Canada
     
    Patrick TJ McPhee, Jan 7, 2004
    #2
    1. Advertising

  3. Rupa

    Unregistered Guest

    Unregistered, Jan 23, 2004
    #3
  4. In article <4designers.com>,
    Unregistered <4designers.com> wrote:
    %
    % There is no substr function in XSLT....

    Excuse me. That should be substring().

    --

    Patrick TJ McPhee
    East York Canada
     
    Patrick TJ McPhee, Jan 25, 2004
    #4
    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. Vijay singh
    Replies:
    1
    Views:
    445
    Martin Honnen
    Nov 4, 2004
  2. Tjerk Wolterink

    XSLT: xsl:variable : help!

    Tjerk Wolterink, Nov 24, 2004, in forum: XML
    Replies:
    10
    Views:
    880
    Morris M. Keesan
    Nov 29, 2004
  3. Replies:
    1
    Views:
    3,637
    A. Bolmarcich
    May 27, 2005
  4. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Help with XSL/XSL:FO for producing revision indicator bar in document.

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Apr 28, 2006, in forum: XML
    Replies:
    6
    Views:
    583
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    May 3, 2006
  5. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    726
    Skybuck Flying
    Oct 4, 2009
Loading...

Share This Page