Solved

Generate html layout from xml

Posted on 2013-10-29
5
369 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using Classic ASP inside HTML pages 2 55
Formatting issues in XSL FO 3 30
read an xml file in perl 2 14
How to loop bootstrap columns which contain database records 9 19
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article discusses how to create an extensible mechanism for linked drop downs.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
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 …

919 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

16 Experts available now in Live!

Get 1:1 Help Now