|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
OK guys, this one has got me stumped.
Im using - <xsl:for-each select="TYRE"> then do what my XSL tells you to do then it prints out my html, but i can only print out one column of data, for example please view http://www.theshadownest.com.au/tyr...stock/tyres.xml What i want to be able to do, is print out two columns of data from my XML, so the table you see there would have a companion table next to it, with more tyre stock in it. So far all i can do is make is print out a second identical table next to it, i dont want this, i want it to read the XML elements, like tyre 1 - - tyre 2 tyre 3 - - tyre 4 tyre 5 - - tyre 6 tyre 7 - - tyre 8 as apposed to tyre 1 - - tyre 1 tyre 2 - - tyre 2 tyre 3 - - tyre 3 tyre 4 - - tyre 4 heres a link to my XSL XSL tyre express most of the top part is just HTML, scroll down to where u see <xsl:template match="EQUUS"> <xsl:for-each select="TYRE"> thats where the XSL really is thanks guys ![]() |
|
#2
|
||||
|
||||
|
This is what I used to solve this problem on my sites.
You would have to set a container to the size of the two columns so that they do not go into more than 2 columns. http://www.htmlhelp.com/reference/css/box/float.html
__________________
Teflon - The Black <desc>Mark This Up</desc> |
|
#3
|
|||
|
|||
|
I'd rather go to a solution like this one, ie: displaying tag having an odd position() into column 1, and those having an even position() into column 2.
Code:
...
<tr>
<td>
<xsl:apply-templates select="//yourtag[(position() mod 2) = 1]" />
</td>
<td>
<xsl:apply-templates select="//yourtag[(position() mod 2) = 0]" />
</td>
</tr>
...
Not tested, but that should work. ![]() |
|
#4
|
|||
|
|||
|
No sorry bro no luck with your above code, instead of displaying tables in two seperate columns, it was formatting them one under the other in one column
eg.. tyre 1 - tyre 2 - tyre 3 - Iv been trying to use the mod position command as well, it should work, i dont understand why it doesnt, iv also tried using a choose staement, with position mod command, but still no luck. Any more help u could offer would be most appreciated. here is what my code looked like after adding in yours, just for your scrutiny <tr> <td> <xsl:apply-templates select="EQUUS[(position() mod 2) = 1]" /> </td> <td> <xsl:apply-templates select="EQUUS[(position() mod 2) = 0]" /> </td> </tr> if i missed something, or applied it worng, please let me know ![]() |
|
#5
|
|||
|
|||
|
Also if i use the code
<tr> <td> <xsl:apply-templates select="EQUUS[(position() mod 2) = 1]" /> </td> <td> <xsl:apply-templates select="EQUUS[(position() mod 2) = 1]" /> </td> </tr> It keeps my formatting of the tables, and prints out two columns but both identical, as soon as i change the second position mod to = 2 it reformats it one column again. so im assuming the xml doesnt understand the second mod position, because my TD cells still remain there, but it just doesnt write anything into them when it it is set to = 2. any ideas |
|
#6
|
|||
|
|||
|
That's right.. if you don't need to have one table row per actual row, then my solution is still fine, I just tested it, and I have two TD's with all the right values below one another.
xml: Code:
<MyRoot> <MyTag Value="001" /> <MyTag Value="002" /> <MyTag Value="003" /> <MyTag Value="004" /> <MyTag Value="005" /> <MyTag Value="006" /> <MyTag Value="007" /> <MyTag Value="008" /> </MyRoot> xsl: Code:
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td class="left">
<xsl:apply-templates select="MyTag[(position() mod 2) = 1]" />
</td>
<td class="right">
<xsl:apply-templates select="MyTag[(position() mod 2) = 0]" />
</td>
</tr>
</table>
+ this template:
<xsl:template match="MyTag">
<xsl:value-of select="@Value" /><br />
</xsl:template>
Don't forget the <br> at the end. This produces the following output: 001 002 003 004 005 006 007 008 But as one HTML row. I'm still checking if doing the same over multiple rows is feasible, I'm not too sure it is. |
|
#7
|
|||
|
|||
|
Hey dude thanks for the help, but i still cant get it to work
i copied your above code and made a new xml/xsl file using your code only, and absolutly nothing appeared when i opened the xml, dont worry i have the files linked correctly, I dont know hey, im stumped, am i using the wrong namespace?, or doctype?? but yeah i couldnt get even your simple code there to work on my end. I then changed your code to Code:
<table border="1" cellpadding="0" cellspacing="0" width ="200" height="200">
<tr>
<td class="left">
<xsl:apply-templates select="MyRoot[(position() mod 2) = 1]" />
</td>
<td class="right">
<xsl:apply-templates select="MyRoot[(position() mod 2) = 0]" />
</td>
</tr>
</table>
and it outputed the xml values but again one under the other, eg.. value 1 value 2 value 3 etc.. why is it not formatting it properly, again, thanks for the help so far |
|
#8
|
|||
|
|||
|
weird.. wouldn't you have forgotten a few stuff ? just to be sure, here's the full code of my xsl file:
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="MyRoot">
<html>
<head>
<title>Test</title>
<style type="text/css">
.left { color: #FF0000; }
.right { color: #0000FF; }
</style>
</head>
<body>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td class="left">
<xsl:apply-templates select="MyTag[(position() mod 2) = 1]" />
</td>
<td class="right">
<xsl:apply-templates select="MyTag[(position() mod 2) = 0]" />
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="MyTag">
<xsl:value-of select="@Value" /><br />
</xsl:template>
</xsl:stylesheet>
That works on my machine. |
|
#9
|
|||
|
|||
|
Dude you are a legend, champion, xml guru.
Ok i got it to work perfect, heres what i did, couldnt have done it without u. OK, first, if you look in my XSL, iv been lazy and used Code:
<xsl:template match="/"> To match the top element of my XML, i should have used the name of the top element (EQUUS) not the / SO then i put your code back into my XSL, eg Code:
<tr> <td> <xsl:apply-templates select="TYRE[position() mod 2 = 1]" /> </td> <td> <xsl:apply-templates select="TYRE[position() mod 2 = 0]" /> </td> </tr> But was still not working, so i thought, wait, if the position tag is now selecting my TYRE 's i dont need the XSL for:each command anymore, so i removed that from my TYRE template. And bang!, works, thanks heaps man, you saved me programming this all again in java. If i could buy you a beer i would, damit wheres that little emoticon with the beer!, not here, oh well. Later and thanks again |
|
#10
|
|||
|
|||
|
Glad you like it
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XML for each (TWO seperate columns of XML data) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|