473,386 Members | 1,867 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,386 software developers and data experts.

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

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:otherwise> SOMETHING HERE THAT I HAVEN'T SORTED OUT YET
</xsl:otherwise>
</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
Jul 20 '05 #1
3 7172
In article <df*************************@posting.google.com> ,
Rupa <ru*********@metier.com> 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
pt**@interlog.com
Jul 20 '05 #2

There is no substr function in XSLT...

Unregistered
-----------------------------------------------------------------------
Posted via http://www.forum4designers.co
-----------------------------------------------------------------------
View this thread: http://www.forum4designers.com/message29485.htm

Jul 20 '05 #3
In article <Gu**********@mail.forum4designers.com>,
Unregistered <Gu**********@mail.forum4designers.com> wrote:
%
% There is no substr function in XSLT....

Excuse me. That should be substring().

--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #4

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

Similar topics

1
by: Son KwonNam | last post by:
When I try <xsl:value-of select="count('/GROUPS/GROUP')"/> on JSTL <x:transform> tag, I got the following error message. org.apache.jasper.JasperException: Can not convert #STRING to a NodeList!...
2
by: S??rgio Nunes | last post by:
Hi, I'm applying a XSL transformation to a XML document. I would like to know if it's possible to include <?..?> in the output header. Example: ===== a.xml: =====
4
by: renderman | last post by:
Hi, I looked through a computergenerated code because I had to edit something manually. I found this line: <xsl:when test="''='FALSE'"> I don't get what this means.
7
by: KJ | last post by:
What does this do: <xsl:apply-templates select="." /> ?
7
by: Scott W Gifford | last post by:
Hello, I'm considering using XML to represent a stream of location information, and XPath to do queries against it. I've got most of it figured out (at least on paper), but I can't figure out...
3
by: tldisbro | last post by:
Hello All, I am trying to use the returned value of the <fo:page-number> element/function in my <xsl:if> test condition. But am unsuccessful in doing so. Is it possible to use it in this fashion...
4
by: Jon | last post by:
Hi, I used XslCompiledTransform with the following Xsl file. The <xsl:text disable-output-escaping="yes"does not work when using XslCompiledTransform to do the trnasform (namely the output...
2
by: riceyeh | last post by:
Hi, What does <xsl:if test="not($values)"mean? What I do not understand is $values? Here, means array? And . = $value means current node is equal to the variable value? So the total meaning is...
3
by: jariwaladivyesh | last post by:
Hi frnds, i have simple XML doc <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="test.xsl"?> <data> <name> Divyesh Jariala</name> </data>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.