Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2005, 07:05 AM
Registered User
 
Join Date: May 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to its_vippy
Default problem while converting xml to html

Hi
I am a newbie to XSLT.
I have got a xml file
of the kind

Code:
<layout>
    <frameset>
        <frame name="headerFrame" src="" size="200" resize="no"></frame>
        <frame name="menuFrame" src="" size="700" resize="no"></frame>
        .
        .
    </frameset>
</layout>
and i want to convert it to a html using a xsl file
i wrote a xsl:
Code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
 
<xsl:template match="/">
    <html>
    <head><title>Samsung OAMP</title></head>
    <frameset rows="200,700">
    <xsl:for-each select="layout/frameset/frame">
        <frame name="{@name}" src="{@src}" noresize="{@resize}"></frame>         
    </xsl:for-each>
    </frameset>
    </html>
</xsl:template>
</xsl:stylesheet>

problem is i am not succeeding without hardcoding the line
<frameset rows="200,700">
i want the rows/cols and sizes to be selected as in xml file

Any help will be appreciated.
well number of nodes is not large there will be only 4 frames
but might be organized in difft. difft. way


 
Old May 30th, 2005, 10:42 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 2.0 you can write

<frameset rows="{string-join(layout/frameset/frame/@size, ',')}">

In 1.0 it's more long-winded:

<frameset>
  <xsl:attribute name="rows">
    <xsl:for-each select="layout/frameset/frame/@size">
      <xsl:value-of select="."/>
      <xsl:if test="position()!=last()">,</xsl:if>
    </xsl:for-each>
  </xsl:attribute>



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 30th, 2005, 09:13 PM
Registered User
 
Join Date: May 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to its_vippy
Default

Hi Michael
i tried it but it didnt work :-s
here is my code
Code:
<frameset>
    <xsl:if test="@split='rows'">
        <xsl:attribute name="rows">
            <xsl:for-each select="layout/frameset/frame/@size">
                <xsl:value-of select="."/>
                <xsl:if test="position()!=last()">,</xsl:if>
            </xsl:for-each>

        </xsl:attribute>
    </xsl:if>
Anyways I have added a split and sizes attribute in <frameset> to become a <frameset split="rows" sizes="200,200,600">
and then i m using
Code:
<xsl:attribute name="rows">
    <xsl:value-of select="@sizes"/>
</xsl:attribute>
which is working.

but in the xml file there may be nested <frameset> tags
can you show me a way how to handle nested tags please





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in transferring data into html from xml. Somesh C# 0 February 7th, 2007 07:43 AM
Problem in Converting xml to sgml pragneshpandya XML 0 November 27th, 2006 01:52 AM
Converting XML to XML (making element mandatory) boondocksaint20 XSLT 8 April 28th, 2006 10:54 AM
converting self-nested xml to html its_vippy XSLT 1 June 1st, 2005 04:47 AM
Converting an XML File into a HTML File ewan XSLT 2 October 4th, 2004 09:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.