p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   problem while converting xml to html (http://p2p.wrox.com/showthread.php?t=29886)

its_vippy May 30th, 2005 07:05 AM

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



mhkay May 30th, 2005 10:42 AM

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

its_vippy May 30th, 2005 09:13 PM

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


All times are GMT -4. The time now is 03:20 AM.

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