Solved

Generate html layout from xml

Posted on 2013-10-29
5
376 Views
Last Modified: 2013-10-30
Dear all,
Looking for XSL that generate html code:
<div id="maincontent">
	<div class="section group">
		<div class="col span_6_of_12">ID=1150</div>
		<div class="col span_3_of_12">ID=1151</div>
		<div class="col span_3_of_12">ID=1152</div>
	</div>
	<div class="section group">
		<div class="col span_3_of_12">ID=1153</div>
		<div class="col span_3_of_12">ID=1154</div>
		<div class="col span_3_of_12">ID=1155</div>
		<div class="col span_3_of_12">ID=1321</div>
	</div>
	<div class="section group">
		<div class="col span_9_of_12">ID=1156</div>
		<div class="col span_3_of_12">ID=1322</div>
	</div>
</div>

Open in new window

using following xml:
<layout>
	<item>
		<id>1150</id>
		<name>admin_LookupTable</name>
		<x>1</x>
		<y>1</y>
		<width>6</width>
		<height>3</height>
	</item>
	<item>
		<id>1151</id>
		<name>admin_LookupTable1</name>
		<x>7</x>
		<y>1</y>
		<width>3</width>
		<height>3</height>
	</item>
	<item>
		<id>1152</id>
		<name>AdministratorPermistionLevel</name>
		<x>10</x>
		<y>1</y>
		<width>3</width>
		<height>3</height>
	</item>
	<item>
		<id>1153</id>
		<name>AdministratorLog</name>
		<x>4</x>
		<y>4</y>
		<width>3</width>
		<height>3</height>
	</item>
	<item>
		<id>1154</id>
		<name>Administrators</name>
		<x>1</x>
		<y>4</y>
		<width>3</width>
		<height>3</height>
	</item>
	<item>
		<id>1155</id>
		<name>admin_ReferedDB</name>
		<x>7</x>
		<y>4</y>
		<width>3</width>
		<height>3</height>
	</item>
	<item>
		<id>1156</id>
		<name>admin_KeyWords1</name>
		<x>1</x>
		<y>7</y>
		<width>9</width>
		<height>3</height>
	</item>
	<item>
		<id>1321</id>
		<name>admin_RedirectLink1</name>
		<x>10</x>
		<y>4</y>
		<width>3</width>
		<height>3</height>
	</item>
	<item>
		<id>1322</id>
		<name>admin_RedirectLink</name>
		<x>10</x>
		<y>7</y>
		<width>3</width>
		<height>3</height>
	</item>
</layout>

Open in new window

xmllayou
0
Comment
Question by:ethar1
  • 3
  • 2
5 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 39610439
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    
    <xsl:output indent="yes"></xsl:output>
    
    <xsl:template match="layout">
        <div id="maincontent">
            <xsl:for-each-group select="item" group-by="y">
                <xsl:sort order="ascending" select="y" data-type="number"/>
                <xsl:variable name="width" select="sum(current-group()/self::item/width)"></xsl:variable>
                <div class="section group">
                    <xsl:for-each-group select="current-group()" group-by="x">
                        <xsl:sort order="ascending" select="x" data-type="number"/>
                        <div class="col span_{width}_of_{$width}">
                            <xsl:text>ID=</xsl:text>
                            <xsl:value-of select="id"/>
                        </div>
                    </xsl:for-each-group>
                </div>
            </xsl:for-each-group>
        </div>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:ethar1
ID: 39610627
could you please change this xsl to MSXML2 processor?
I may open a new question if you like..
0
 

Author Comment

by:ethar1
ID: 39610633
I got this error:

msxml3.dll error '80004005'

Keyword xsl:template may not contain xsl:for-each-group.
0
 

Author Comment

by:ethar1
ID: 39611153
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39612817
Hi, I did not realize you needed an XSLT1 solution, I answered in the new question you posted
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question