Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Generate html layout from xml

Posted on 2013-10-29
5
Medium Priority
?
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 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
 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

722 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