Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arranging xml elements due to parent-child

Status
Not open for further replies.

ozane

Technical User
Feb 3, 2005
57
TR
hi,
i have a well formed xml file. wonna view it on browser via xsl file.
but the structure should be like in xml. i mean the tabs in browser should be set according to xml automatically. as an example:
XML
<a>
<b/>
<c>
<d/>
</c>
</a>

Browser view
a: value
b:value
c:value
d:value

is there a way or script to do it automatically??
 
Why not try:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:template match="/">
    <html>
      <head>
        <title>XML view</title>
        <style type="text/css">p{margin: 0;}</style>
      </head>
      <body>
        <xsl:for-each select="node()">
          <xsl:call-template name="displayNodes">
            <xsl:with-param name="nodes" select="."/>
            <xsl:with-param name="indent" select="0"/>
          </xsl:call-template>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
  <xsl:template name="displayNodes">
    <xsl:param name="nodes"/>
    <xsl:param name="indent"/>
    <xsl:if test="local-name($nodes)!=''">
      <p style="margin-left: {$indent}em">
        <xsl:value-of select="local-name($nodes)"/>
        <xsl:text>:</xsl:text>
        <xsl:value-of select="$nodes/text()"/>
      </p>
    </xsl:if>
    <xsl:if test="$nodes/node()">
      <xsl:for-each select="$nodes/node()">
        <xsl:call-template name="displayNodes">
          <xsl:with-param name="nodes" select="."/>
          <xsl:with-param name="indent" select="$indent + 1"/>
        </xsl:call-template>
      </xsl:for-each>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
 
ooppss :) thanks. will try.

but it will be hard to adapt my xsl to yours :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top