Solved

Generate html layout from xml

Posted on 2013-10-29
5
365 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
Comment Utility
<?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
Comment Utility
could you please change this xsl to MSXML2 processor?
I may open a new question if you like..
0
 

Author Comment

by:ethar1
Comment Utility
I got this error:

msxml3.dll error '80004005'

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

Author Comment

by:ethar1
Comment Utility
0
 
LVL 60

Expert Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
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 …

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now