1

This is my test XML in this XML i have child element: INSTRUMENT and sub child element: INSTRUMENT/issuer and could be so on ... 5002199 10001 686184SE3

<INSTRUMENT>
    <type>FI</type>
    <issuer>
        <FICode>123456</FICode>
        <name>Test</name>
        <city>SF</city>
        <state>CA</state>
    </issuer>

    <issueDate>2011-06-22-05:00</issueDate>
    <maturityDate>2016-06-22-05:00</maturityDate>
    <firstCouponDate>2011-07-22-05:00</firstCouponDate>
    <lastCouponDate>2016-05-22-05:00</lastCouponDate>
    <couponRate>2.0</couponRate>

    <paymentFrequency>12</paymentFrequency>

    <callSchedule>
        <notice>15</notice>
        <timing>0</timing>
        <call id="1">
            <startDate>2011-12-22-05:00</startDate>
            <type>2</type>
            <freq>M</freq>
        </call>
    </callSchedule>
</INSTRUMENT>
<Commision>7.0</Commision>
<price>100.0</price>

I want to display this data in HTML tabular form, and run time the xml element could be any thing, so i can't hard code the element or subelement name i was trying follwinf XSL

<xsl:template match="/">
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="*">
    <table border="1" width="1000">
        <tr>
            <td class="section_head">Key</td>
            <td class="section_head">Value</td>
        </tr>
        <xsl:for-each select="*" >
            <tr>
                <td>
                    <xsl:value-of select="name(.)" />
                </td>
                <td>
                    <xsl:value-of select="." />
                </td>
            </tr>
        </xsl:for-each>
    </table>
</xsl:template>

the HTM Child INSTRUMENT and issuer and callSchedule is comming in tabular form is there any way i can iterate XSL recursivley to create HTML child table for XML child elements ?

Key Value ID 5002199 Code 10001 cusip 686184SE3 INSTRUMENT FI 123456 Test SF CA 2011-06-22-05:00 2016-06-22-05:00 2011-07-22-05:00 2016-05-22-05:00 2.0 12 15 0 2011-12-22-05:00 100.0 2 M 2012-01-22-05:00 100.0 2012-02-22-05:00 100 Commision 7.0 price 100.0 alloc 100
1
  • Do you want a separate table for the children? Commented Jun 17, 2011 at 8:26

1 Answer 1

2

I am not exactly sure what you are after here. It looks like you want to convert the nodes into name/value pairs and nest the html tables according to the XML hierarchy. Here is a bit of recursion that addresses the problem of not knowing the node names at runtime. Hopefully it well help you get started with this. If it is not what you are looking for you can use it to clarify your question:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">   
    <html>
      <table>
        <xsl:apply-templates/>
      </table>  
    </html> 
  </xsl:template>

  <xsl:template match="*[count(*) = 0]">   
    <tr>
      <td>
        <xsl:value-of select="name(.)" />
      </td>
      <td>
        <xsl:value-of select="." />
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="*[count(*) > 0]">  
    <tr>
      <td>
        <xsl:value-of select="name(.)" />
      </td>
      <td>
        <table>
          <xsl:apply-templates/>             
        </table>
      </td>
    </tr>     
  </xsl:template>
</xsl:stylesheet>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.