Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Wed, 4 Jun 2008 11:01:22 -0700 (PDT),    group: microsoft.public.xsl        back       


Transform nested XML-Data to nested HTML-Structure   
Hello everyone,

can anyone please help me with the following problem?

My XML is like:
<root>
<series>
~~<entry>
~~~~<field1>AA1</field1>
~~~~<field2>
~~~~~~<blah1>BBB1</blah1>
~~~~~~<blah2>BBB2</blah2>
~~~~~~<blah3>
~~~~~~~~<other1>GGGR1</other1>
~~~~~~~~<other2>GGGR2</other1>
~~~~~~</blah3>
~~~~</field2>
~~~~<field3>
~~~~~~<blah1>CCC1</blah1>
~~~~~~<blah2>CCC2</blah2>
~~~~~~<blah3>
~~~~~~~~<other1>GGGR11</other1>
~~~~~~~~<other2>GGGR22</other2>
~~~~~~</blah3>
~~~~</field3>
~~</entry>
~~<entry>
~~~~<field1>AA2</field1>
~~~~<field2>BB2</field2>
~~~~<field3>CC2</field3>
~~</entry>
~~<entry>
~~~~<field1>AA3</field1>
~~~~<field2>BB3</field2>
~~~~<field3>CC3</field3>
~~</entry>
</series>
<series>
...
</series>
<series>
...
</series>
</root>

No now I'd like to have a HTML page so that:
- a series becomes a <table>
- an entry becomes a <tr>
- field1, field2, field3 become <th> and the values of those tags
become the <td>
---> so far so good, I've got coding which does that (listed below)
however only up to this level.
Now I need to find a way to handle the nested structures inside (and I
was thinking of <table> inside the <table>), so that (again) the tags
become table-headers (<th>) and the values besome <td>.
Do you have any idea of how to do that?
Most of all, it must be generic -> I do not have to know the names of
the tags.

<xsl:for-each select="/root/*">
  <table>
  <tr><xsl:for-each select="./*/*"> <!-- one loop for the first roe of
the table (names of tags) -->
      <xsl:if test="count(parent::*/preceding-sibling::*) = 1"> <!--
print the names only once for the first row only -->
        <td><xsl:value-of select="name()"/></td>
      </xsl:if>
  </xsl:for-each></tr>
  <xsl:for-each select="./*"> <!-- another loop for the data in the
table (tags values) -->
    <tr><xsl:for-each select="node()">
      <td><xsl:value-of select="."/></td>
    </xsl:for-each></tr>
  </xsl:for-each>
  </table>
</xsl:for-each>

Help is appreciated!
Hristo
date: Wed, 4 Jun 2008 11:01:22 -0700 (PDT)   author:   starlight

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us