my current output is as below:
item1 item2
item3 item4
item5 item6
item7 item8
item9 item10
I want the output to be shown as below.
item1 item6
item2 item7
item3 item8
item4 item9
item5 item10
Can I do this with XSLT?
can not attach my xml/xsl files as they r huge.
your help is much appreciated.
thanks,
nayana
Hi Nayana
assume input(must be welformed XML) is
item1 item2
item3 item4
item5 item6
item7 item8
item9 item10
try this:
<xsl:stylesheet version=“1.0” xmlns:xsl=“XSLT Namespace”>
<xsl:output method=“xml” indent=“yes” version=“1.0”/>
<xsl:template match=“/root”>
<xsl:variable name=“nodes” select=“l|r”/>
<xsl:variable name=“half” select=“count($nodes) div 2”/>
<xsl:apply-templates select=“l|r”>
<xsl:with-param name=“nodes” select=“$nodes”/>
<xsl:with-param name=“half” select=“$half”/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match=“l|r”>
<xsl:param name=“nodes”/>
<xsl:param name=“half”/>
<xsl:variable name=“position” select=“position()”/>
<xsl:if test=“position() <= $half”>
<xsl:value-of select=“.”/>
<xsl:value-of select=“$nodes[position()=$position+$half]”/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Result is
<?xml version="1.0" encoding="utf-8"?>
item1
item6
item2
item7
item3
item8
item4
item9
item5
item10
Cheers
Uli
Hi Uli…thanks for ur feedback
I am trying to do some data formatting with my xml.
For eg …my xml is as below
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="stylesheet/webtemplate.xsl"?>
9210i
$300
9210
$250
9110
$50
8910i/7600
$300
8910
$170
8855
$110
8850/8890
$80
7110/6210
$25
8310
$110
8210
$60
8250
$80
7650
$200
7610
$550
6820
$240
6800/5100
$130
6610i
$220
6610/6100
$160
6230
$410
6510
$90
6150/6110/5110
$10
6108/3300
$170
6220/5140
$230
5210/3610/1100
$60
3660
$300
3650
$250
3530
$70
3310/3330
$45
2100
$70
N-gage QD
$220
and xslt is as below:
<xsl:stylesheet xmlns:xsl =
“XSLT Namespace” version =
“1.0” >
<xsl:output method=“html” indent=“yes” />
<xsl:template match=“//Phones” >
Yaddayadda…
<xsl:apply-templates />
</xsl:template>
<xsl:template match=“model[position() mod 2 = 1]”>
<xsl:value-of select=“./name” />
<xsl:value-of select=“./price” />
<xsl:value-of select=“following-sibling::node()[position() = 1]/name” />
<xsl:value-of select=“following-sibling::node()[position() = 1]/price” />
</xsl:template>
<xsl:template match=“name”/>
<xsl:template match=“price”/>
</xsl:stylesheet>
and my current output is as shown below
::: CURRENT OUTPUT:::
xsl transformation output:
9210i $300 9210 $250
9110 $50 8910i/7600 $300
8910 $170 8855 $110
8850/8890 $80 7110/6210 $25
8310 $110 8210 $60
8250 $80 7650 $200
7610 $550 7250i $220
which is similar to the following format…
I need to change the output format as below:
:::EXPECTED OUTPUT:::
How do i do that? anybody can help…?
Thanks,
Nayana