|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Ok what im wondering is, is there a way to make your XSL print out your xhtml/xml from the last entry to the first entry, so the output on the webpage, is
1. = last entry 2. = 2nd last entry .. .. .. .. 50. = first entry because normally if you use for:each in your xsl to output your xml, it will do it from the first xml entry to the last xml entry all i wanna do is reverse it ![]() example xml Code:
<main>
<entry 1>
<tags>Print me last</tags>
</entry 1>
<entry 2>
<tags>Print me second</tags>
</entry 2>
<entry 3>
<tags>Print me first</tags>
</entry 3>
</main>
so normally a for:each xsl statement will print out your xml like 1. Print me last 2. Print me second 3. Print me first i want it to print out like this 1. Print me first 2. Print me second 3. Print me last I wanna do this for more than 3 xml entries, so no one give me dodgy solutions of switching the first and last entry only. ![]() |
|
#2
|
|||
|
|||
|
it's just a quick suggestion, untested, and absolutely not sure it's possible, but if you could always have a look at the xpath functions that allow you to work on the last node in a given context:
/main/entry[last()] then use a loop to get the preceding siblings one by one, by using preceding-sibling:: Refer to xpath tutorials if you're not familiar with these. Sorry I can't provide you with a full solution atm, but if you go into that direction, you should be able to get results. good luck. Btw, if you make progress on your own and get stuck at some point, post it, i'll try to provide further assistance ![]() |
|
#3
|
|||
|
|||
|
WIll look into xpaths, shouldnt be that difficult, and the results will be worth it.
If i get stuck i will defenently enlist your help man, then we can market our solution. ![]() |
|
#4
|
|||
|
|||
|
Ok i might try this, and see how it works on weekend, im at work now
XML Code:
<tag lineNo="1"> <tag lineNo="2"> <tag lineNo="3"> <tag lineNo="4"> My XSL Code:
<xsl:for-each select = "./tag"> <xsl:sort select="@lineNo" order="descending" data-type="number"/> <xsl:number value = "./@lineNo" format="1."/> <xsl:value-of select ="."/> </xsl:for-each> I dont know if it it will work, but it may be a better option than xpaths, its relatively simple to, just a pain to add lineNo all the time. then again its perl output so it wont be that bad. |
|
#5
|
|||
|
|||
|
found some time to dig into it:
xml: Code:
<main>
<entry>
<tags>Print me 5th</tags>
</entry>
<entry>
<tags>Print me 4th</tags>
</entry>
<entry>
<tags>Print me 3rd</tags>
</entry>
<entry>
<tags>Print me 2nd</tags>
</entry>
<entry>
<tags>Print me 1st</tags>
</entry>
</main>
xsl: Code:
<xsl:template match="main">
<html>
<body>
<xsl:apply-templates select="/main/entry[last()]" />
</body>
</html>
</xsl:template>
<xsl:template match="entry">
<xsl:value-of select="tags"/>
<br />
<xsl:apply-templates select="preceding-sibling::entry[1]" />
</xsl:template>
output: Code:
Print me 1st Print me 2nd Print me 3rd Print me 4th Print me 5th Initial apply-templates positions you on the very last entry tag, then within the entry template, you apply-templates again by specifying that you want the entry tag that is IMMEDIATELY preceding the current one, this is done by using preceding-sibling::entry[1], using it without the [1] didn't work. ![]() |
|
#6
|
|||
|
|||
|
Im definently gonna try that one out, the one i posted was hell buggy.
It will be interesting to see if i can get your code to display, in line with my other post about two columns of XML, thanks again. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Reversing XML readout (upside down upside down) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|