Jump to content

How Can I Re-group 2d Data From Columns To Rows?


couling
 Share

Recommended Posts

I'm trying to regroup a table from columns to rows using XSLT.so far all my searches have turned up nothing.Can anyone give me any advice on this. Is it even possible?Example:

<table>	<column>		<val>a</val>		<val>b</val	</column>	<column>		<val>c</val>		<val>d</val>	</column>	<column>		<val>e</val>		<val>f</val>	</column></table>

should become:

<table>	<tr>		<td>a</td>		<td>c</td>		<td>e</td>	</tr>	<tr>		<td>b</td>		<td>d</td>		<td>f</td>	</tr></table>

Link to comment
Share on other sites

I'm trying to regroup a table from columns to rows using XSLT.so far all my searches have turned up nothing.Can anyone give me any advice on this. Is it even possible?Example:
<table>	<column>		<val>a</val>		<val>b</val	</column>	<column>		<val>c</val>		<val>d</val>	</column>	<column>		<val>e</val>		<val>f</val>	</column></table>

should become:

<table>	<tr>		<td>a</td>		<td>c</td>		<td>e</td>	</tr>	<tr>		<td>b</td>		<td>d</td>		<td>f</td>	</tr></table>

if you need to rewrite a xml you need a parser to do that.create a php file with a DOM parser.<?php$pass=new DOMDocument();$pass->load('yourXmlDoc.xml');$variable=$pass->getElementsByTagName("OldXmlTag");$newTag=$heighttmp->item(0)->nodeValue; // take all the tags like thisprint $xmlDoc->saveXML();?>this might work for you.i haven't test it yet.But looking forward to do it.you better visit this link http://www.php.net/manual/en/domdocument.construct.php .Here you will find all the php functions related to XML manupulations.
Link to comment
Share on other sites

@sasanka XSLT is more suitable for this than DOM, though indeed DOM is a possible way of doing this. If you have a particular idea on how grouping can be done in DOM, please go ahead.Grouping is my weak spot in XSLT, so I can't really help you there. The best I can do is give you this article on XSLT that shows how to, among other things, use xsl:key to do grouping.

Link to comment
Share on other sites

  • 3 weeks later...

don't know if this will help, its a variation of the dynamic table I submitted quite some time ago. It calculates the number of rows and columns to build based on the structure of the XML then recursively calls itself to build the desired ouput

		<xsl:stylesheet 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"			version="1.0">			<xsl:output method="html" />			<xsl:variable name="rows" select="count(//column[1]/val)" />			<xsl:variable name="cols" select="count(//column)" />			<xsl:template match="/">				<table border="1" >					<xsl:call-template name="BuildRows" />				</table>			</xsl:template>			<xsl:template name="BuildRows">				<xsl:param name="RowNumber" select="1"/>				<tr>					<xsl:apply-templates select="//val[position() = $RowNumber]" />				</tr>				<xsl:if test="$RowNumber < $rows">					<xsl:call-template name="BuildRows">						<xsl:with-param name="RowNumber" select="$RowNumber+1"/>					</xsl:call-template>				</xsl:if>			</xsl:template>			<xsl:template match="val">				<td>					<xsl:value-of select="."/>				</td>			</xsl:template>		</xsl:stylesheet>

result is a c e b d f

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...