473,466 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

xsl:if and nested td tag problem

I'm using XSL to transform an XML document to HTML, however I'm encountering
the following problem.I want to test a couple of values using an xsl:if
statement and then print a couple of HTML tags only when the condition is
met:

<xsl:if test="position() = $countPar">

</td>

<td width="50%" valign="top">

</xsl:if>

However, the parser takes offence at the td closing tag following an xsl:if
opening tag. What do I do?

Thanks

Steven
Nov 11 '05 #1
3 3255
Steven wrote:
I've got a number of elements that each contain a paragraph of text, I want
to put that text into 2 columns of a HTML table, half the paragraphs in one
column, half in the other. So I loop through the paragraph elements (using
xsl:for-each), outputting each one in turn. When I'm on the middle element I
want to output HTML that will close the tag for the current cell and start
the new cell (or column). After that I just output the rest of paragraph
elements. So what I've been trying is to use an xsl:if statement in the
middle of the xsl:for-each to see if I'm on the middle element and then
creating the new cell at that point.

Well, again, you can't program in XSLT as in C or Java, it's not imperative
procedural language. You have to learn to think in a declarative way.
So instead of processing paragraph and closing/opening cells XSLT requires you
just to declare that you want two cells, half of text in one and the rest in
the second.
Why don't you post an example of you XML and the desired result?
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Yeah, see what you mean. This is my first stab at XSL and I'm still not
certain of what it is and isn't capable of. Now that you've confirmed that
this won't be possible, and suggested the correct way of considering the
problem I've found a solution - to do the loop twice, once in each cell. In
the first cell I'll check that the element number is less that half of the
total number of elements, and in the second cell that only those elements
over half way through the total are output. Simple.

Thanks for your help Oleg.

Steven
Nov 11 '05 #3
Steven wrote:
Yeah, see what you mean. This is my first stab at XSL and I'm still not
certain of what it is and isn't capable of. Now that you've confirmed that
this won't be possible, and suggested the correct way of considering the
problem I've found a solution - to do the loop twice, once in each cell. In
the first cell I'll check that the element number is less that half of the
total number of elements, and in the second cell that only those elements
over half way through the total are output. Simple.

Yes, but not really effective. Try something like this: consider the following
XML fragment:
<foo>
<para>text1</para>
<para>text2</para>
<para>text3</para>
<para>text4</para>
</foo>

Then to split para elements into 2 cells:
<xsl:template match="foo">
<xsl:variable name="size" select="count(para)"/>
<td>
<xsl:apply-templates select="para[position() &lt;= $size div 2]"/>
</td>
<td>
<xsl:apply-templates select="para[position() > $size div 2]"/>
</td>
</xsl:template>

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4

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

Similar topics

3
by: Steven | last post by:
I'm using XSL to transform an XML document to HTML, however I'm encountering the following problem.I want to test a couple of values using an xsl:if statement and then print a couple of HTML tags...
3
by: Lizard | last post by:
OK, total newbie here, so this may be a mind-numbingly dumb question AND I may be phrasing it badly. I have an xsl:template which looks like this: <xsl:template match="LoanRecord"> <hr>...
9
by: Andrea Maschio | last post by:
Hi, i have a terrible noobie frustration formatting an XML file like this: <Dipendente Id="1" Anno="2003" Nome="pippo" Cognome="pippi" Nato_il="10/03" Email="pippo@emailprovider.it" Esito="ok"/>...
2
by: Jørn Tommy Kinderås | last post by:
I need to get nodes in a xml file that match one out of two parameters...but how can I create a or statemement with <xsl:if>? E.G ---xml-- ... <movie> <title>T2</title> </movie> <movie>
3
by: Eric Theil | last post by:
I'm at my wit's end with this one. Within an xsl:if test, I'm not able to get 2 variables to properly evaluate if one of them is wrapped within a string function. <!-- This works --> <xsl:if...
2
by: websls | last post by:
I tried to do this : <xsl:if test="ToutCompris"> some output </xsl:if> ToutCompris is a boolean element in my XML file My problem is the output is parse even when ToutCompris is false I...
5
by: Luke Vogel | last post by:
Hi all, Probably a really basic question, but I cant find an answer ... I have an xml file of books something like: <product> <isbn>0-735-61374-5</isbn> <title>Microsoft Visual Basic Step By...
4
by: Doulos05 | last post by:
Ok, this seems like it should be easy, but it has escaped me. Here is my xml file: <ref_sheet> <item> <date>2007/04/06</date> <product>124567</product> <description>TAB...
4
by: mark4asp | last post by:
I'm getting a problem with this code and I think the offending linke is : <xsl:if test="$folder = 'Search'"> I want to test the value of the Folder element for a value of precisely "Search"...
4
by: grbeal | last post by:
How do I test for a child element with xsl if condition? We have a vendor application that outputs an XML file containing records of School Closings due to inclement weather. That XML file gets...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.