Click to See Complete Forum and Search --> : xml to xml - xsl looping


sunkab
December 12th, 2003, 05:31 PM
i have a xml which has data in blocks(diff elements seperated only by attribute). I have take one value from each block and put them together in a seperate block.The xml looks like


<input>
<input.voltage counter="0">
<value>1</value>
</input.voltage>
<input.voltage counter="1">
<value>2</value>
</input.voltage>
<input.voltage counter="2">
<value>3</value>
</input.voltage>
</input>

<output>
<output.voltage counter="0">
<value>4</value>
</output.voltage>
<output.voltage counter="1">
<value>5</value>
</output.voltage>
<output.voltage counter="2">
<value>6</value>
</output.voltage>
</output>

i am looking for a output in this format:
<DataArray>
<DataCell>1</DataCell>
<DataCell>4</DataCell>
</DataArray>
<DataArray>
<DataCell>2</DataCell>
<DataCell>5</DataCell>
</DataArray>
<DataArray>
<DataCell>3</DataCell>
<DataCell>6</DataCell>
</DataArray>

Any help , pointers will be appreciated

thanks

khp
December 12th, 2003, 06:24 PM
You could write a input.voltage template like this


<xsl:template match="input.voltage">
<DataArray>
<xsl:variable name="counter">
<xsl:value-of select="@counter"/>
</xsl:variable>
<DataCell>
<xsl:value-of select="value/text()"/>
</DataCell>
<DataCell>
<xsl:value-of select="//output.voltage[$counter=@counter]/value/text()"/>
</DataCell>
</DataArray>
</xsl:template>