|
top
|
 Subject: Transform Name Value pairs into Table Structure. Author: (Deleted User) Date: 28 Feb 2008 09:44 AM
|
Hi,
the most efficient solution would involve using xsl:key, but it could be too hard to understand: try something simpler, like this
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<fields>
<xsl:for-each select="Fields/*">
<xsl:if test="substring(name(),1,5)!=substring(name(preceding-sibling::*[1]),1,5)">
<xsl:variable name="table" select="substring(name(),1,5)"/>
<xsl:element name="{$table}">
<xsl:for-each select=". | following-sibling::*[substring(name(),1,5)=$table]">
<xsl:if test="substring(name(),1,11)!=substring(name(preceding-sibling::*[1]),1,11)">
<xsl:variable name="row" select="substring(name(),7,4)"/>
<xsl:element name="{$row}">
<xsl:for-each select=". | following-sibling::*[substring(name(),1,10)=concat($table,'_', $row)]">
<xsl:element name="{substring(name(),12)}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:if>
</xsl:for-each>
</fields>
</xsl:template>
</xsl:stylesheet>
Hope this helps,
Alberto
|
|
|