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 July 9th, 2008, 10:40 AM
Authorized User
 
Join Date: Jul 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to adjust the table display for dynamic xml fi

Processor - XSLT 1.0
platform - windows XP

Hi, Can any one help with this.
I am newbie to XML and XSLT , my requirement is to display the xml data in the Internet Explorer for the given XML file.
Here part of the XML source code is given below.

  <Instance>
      <DataSet>
        <Data>da1</Data>
      </DataSet>
      <DataSet>
        <Data>te7</Data>
      </DataSet>
      <DataSet>
        <Data>da2</Data>
      </DataSet>
      <DataSet>
        <Data>da3</Data>
      </DataSet>
      <Instance>
        <DataSet>
          <Data>da4</Data>
        </DataSet>
        <DataSet>
          <Data>da5</Data>
        </DataSet>
        <DataSet>
          <Data>data6</Data>
        </DataSet>
        <DataSet>
          <Data>data7</Data>
        </DataSet>
        <DataSet>
          <Data>data8</Data>
        </DataSet>
      </Instance>
      <Instance>
        <DataSet>
          <Data>dataA</Data>
        </DataSet>
        <DataSet>
          <Data>dataB</Data>
        </DataSet>
        <DataSet>
          <Data>dataC</Data>
        </DataSet>
        <DataSet>
          <Data>dataD</Data>
        </DataSet>
        <DataSet>
          <Data>dataE</Data>
        </DataSet>
      </Instance>
      <Instance>
        <DataSet>
          <Data>dataQ</Data>
        </DataSet>
        <DataSet>
          <Data>dataW</Data>
        </DataSet>
        <DataSet>
          <Data>dataE</Data>
        </DataSet>
        <DataSet>
          <Data>dataR</Data>
        </DataSet>
        <DataSet>
          <Data>dataT</Data>
        </DataSet>
      </Instance>
    </Instance>
    <Instance>
      <DataSet>
        <Data>007</Data>
      </DataSet>
      <DataSet>
        <Data>te8</Data>
      </DataSet>
      <DataSet>
        <Data>A</Data>
      </DataSet>
      <DataSet>
        <Data>B</Data>
      </DataSet>
      <Instance>
        <DataSet>
          <Data>C</Data>
        </DataSet>
        <DataSet>
          <Data>D</Data>
        </DataSet>
        <DataSet>
          <Data>E</Data>
        </DataSet>
        <Instance>
          <DataSet>
            <Data>F</Data>
          </DataSet>
          <DataSet>
            <Data>G</Data>
          </DataSet>
        </Instance>
        <Instance>
          <DataSet>
            <Data>H</Data>
          </DataSet>
          <DataSet>
            <Data>I</Data>
          </DataSet>
        </Instance>
        <Instance>
          <DataSet>
            <Data>J</Data>
          </DataSet>
          <DataSet>
            <Data>K</Data>
          </DataSet>
        </Instance>
      </Instance>
      <Instance>
        <DataSet>
          <Data>L</Data>
        </DataSet>
        <DataSet>
          <Data>M</Data>
        </DataSet>
        <DataSet>
          <Data>N</Data>
        </DataSet>
        <Instance>
          <DataSet>
            <Data>O</Data>
          </DataSet>
          <DataSet>
            <Data>P</Data>
          </DataSet>
        </Instance>
        <Instance>
          <DataSet>
            <Data>Q</Data>
          </DataSet>
          <DataSet>
            <Data>R</Data>
          </DataSet>
        </Instance>
      </Instance>
    </Instance>

i need the output as show below,
+---------------------------------- ---------------------------------+
!da1 !te7! da2 ! da3 ! da4 ! da5 ! data6 ! data7 ! data8 !
! ! ! ! !-------+-------+---------+---------!---------!
! ! ! ! ! daA ! daB ! dataC ! dataD ! dataE !
! ! ! ! !-------+-------+---------+---------+---------!
! ! ! ! ! daQ ! daW ! dataE ! dataR ! dataT !
!----+---+-----+-------+-------+-------+---------+---------+---------!
!007 !te8! A ! B ! C ! D ! E ! F ! G !
! ! ! ! ! ! ! !---------+---------!
! ! ! ! ! ! ! ! H ! I !
! ! ! ! ! ! ! !---------+---------!
! ! ! ! ! ! ! ! J ! K !
! ! ! ! !-------+-------+---------+---------+---------!
! ! ! ! ! L ! M ! N ! O ! P !
! ! ! ! ! ! ! !---------+---------!
! ! ! ! ! ! ! ! Q ! R !
!----!---!-----!-------!-------!-------!---------!---------!---------!

I hope you get what i need, the logic is to create a new row where the "instance" element (just as show above) has been used.
I had to display the table in internet explorer for given xml which may be some other table structure.
can some one help me with this.

Note: Table output Format shown above is not properly aligned ( though i edited with patience) it is not Exactly displaying here what i required, hope u copy the same thing in ur notepad..with little editing clearing only the space you get the right one


Venki
__________________
Venki
 
Old July 9th, 2008, 11:11 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This is certainly do-able, but I'm sorry, it's not do-able in five minutes. I would have to allow myself a day for it and several false starts, and that goes beyond the help I can give anyone for free. It's especially difficult if you want to run it in IE, because that means you're constrained to XSLT 1.0.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 9th, 2008, 11:22 AM
Authorized User
 
Join Date: Jul 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mhkay
 This is certainly do-able, but I'm sorry, it's not do-able in five minutes. I would have to allow myself a day for it and several false starts, and that goes beyond the help I can give anyone for free. It's especially difficult if you want to run it in IE, because that means you're constrained to XSLT 1.0.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
First of all thanks for your reply Michale,
yes my requirement is to display it in IE, Anyhow i have managed to get the rowspan value
and passing that as a parameter to the template which is used to in <td> tag as follows


<xsl:template match="DataSet">

  <xsl:param name="RowSpan"/>

  <td rowspan="$Rowspan">


      <xsl:apply-templates select="./Data"/>
  </td>

</xsl:template>

but the above code <td rowspan="$Rowspan"> is not taking effect, how do we make that value of the Variable "$Rowspan" to know to HTML tag <td>?



Venki
 
Old July 9th, 2008, 11:24 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Use
Code:
<td rowspan="{$RowSpan}">
--
  Martin Honnen
  Microsoft MVP - XML
 
Old July 9th, 2008, 11:28 AM
Authorized User
 
Join Date: Jul 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Martin Honnen
 Use
Code:
<td rowspan="{$RowSpan}">
--
  Martin Honnen
  Microsoft MVP - XML
Yes, tried that code Martin, but that is showing the following error in IE

A reference to variable or parameter 'Rowspan' cannot be resolved. The variable or parameter may not be defined, or it may ...


Venki
 
Old July 9th, 2008, 11:31 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You want rowspan="{$RowSpan}"

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 9th, 2008, 11:33 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Can you show use the complete template?
And make sure you use the same spelling including the case for instance in your original post you have <xsl:param name="RowSpan"/> but then rowspan="$Rowspan"> so you have a different spelling which can't work.

--
  Martin Honnen
  Microsoft MVP - XML
 
Old July 9th, 2008, 11:47 AM
Authorized User
 
Join Date: Jul 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, that's the mistake i made , which used as
<td rowspan="{Rowspan}">

i am getting the display with no error but not the desired one, seems like rowspan doesn't takes effect;

i leave the full code i am using, if anyone has time please go through it;

<xsl:template match="Instance">

    <xsl:call-template name="Instance">
      <xsl:with-param name="previous" select="/.."/>
      <xsl:with-param name="listNodes" select="."/>
    </xsl:call-template>

</xsl:template>



<xsl:template name="Instance">
  <xsl:param name="previous" select="/.."/>
  <xsl:param name="listNodes" select="."/>

    <xsl:choose>
          <xsl:when test="count($listNodes/Instance)=0">

            <tr>


              <xsl:if test="normalize-space($previous)!=''">
                <xsl:for-each select="$previous">

                  <xsl:apply-templates select="./DataSet">
                     <xsl:with-param name="RowSpan">

                    <xsl:call-template name="CalcRowSpan">
                        <xsl:with-param name="nodeList" select="./Instance"/>
                    </xsl:call-template>

                    </xsl:with-param>
                  </xsl:apply-templates>

                </xsl:for-each>
              </xsl:if>


              <xsl:apply-templates select="$listNodes/DataSet">
                  <xsl:with-param name="RowSpan">

                  <xsl:call-template name="CalcRowSpan">
                     <xsl:with-param name="nodeList" select="$listNodes/Instance"/>
                  </xsl:call-template>

                  </xsl:with-param>
              </xsl:apply-templates>

            </tr>

          </xsl:when>
          <xsl:otherwise>


            <xsl:call-template name="Instance">




              <xsl:with-param name="previous" select="$previous | $listNodes"/>


              <xsl:with-param name="listNodes" select="$listNodes/Instance[1]"/>


            </xsl:call-template>

            <xsl:for-each select="$listNodes/Instance[position()>1]">
              <xsl:call-template name="Instance">


                <xsl:with-param name="listNodes" select="."/>
              </xsl:call-template>
            </xsl:for-each>

          </xsl:otherwise>
    </xsl:choose>
</xsl:template>




<xsl:template match="DataSet">

  <xsl:param name="RowSpan"/>

  <td rowspan="0">


      <xsl:apply-templates select="./Data"/>
  </td>

</xsl:template>



<xsl:template match="Data">
  <p>
    <xsl:copy-of select="text()"/>
  </p>
</xsl:template>




<xsl:template name="CalcRowSpan">
  <xsl:param name="nodeList"/>
  <xsl:choose>
    <xsl:when test="count($nodeList)=1">
      <xsl:choose>

        <xsl:when test="count($nodeList/Instance)>1">
          <xsl:variable name="Result1">
            <xsl:call-template name="CalcRowSpan">
              <xsl:with-param name="nodeList"
                select="$nodeList/Instance[1]"/>
            </xsl:call-template>
          </xsl:variable>
          <xsl:variable name="Result4">
            <xsl:call-template name="CalcRowSpan">
              <xsl:with-param name="nodeList"
                select="$nodeList/Instance[position()>1]"/>
            </xsl:call-template>
          </xsl:variable>
          <xsl:value-of select="$Result1 + $Result4"/>
        </xsl:when>

        <xsl:otherwise>
           <xsl:value-of select="number(1)"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>

    <xsl:when test="count($nodeList)=0">
        <xsl:value-of select="number(1)"/>
    </xsl:when>

    <xsl:otherwise>
        <xsl:variable name="result2">
          <xsl:call-template name="CalcRowSpan">
            <xsl:with-param name="nodeList"
               select="$nodeList[1]"/>
          </xsl:call-template>
        </xsl:variable>

        <xsl:variable name="result3">
          <xsl:call-template name="CalcRowSpan">
            <xsl:with-param name="nodeList"
               select="$nodeList[position()>1]"/>
          </xsl:call-template>
        </xsl:variable>

        <xsl:value-of select="$result2 + $result3"/>
    </xsl:otherwise>

  </xsl:choose>
</xsl:template>

Venki
 
Old July 10th, 2008, 09:53 AM
Authorized User
 
Join Date: Jul 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mhkay
 This is certainly do-able, but I'm sorry, it's not do-able in five minutes. I would have to allow myself a day for it and several false starts, and that goes beyond the help I can give anyone for free. It's especially difficult if you want to run it in IE, because that means you're constrained to XSLT 1.0.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Hello Michale,
      Can you tell me from where to start, based on what i have to make an Algorithm? so that i can proceed. can you please help me this.


Venki





Similar Threads
Thread Thread Starter Forum Replies Last Post
help writing dynamic form data to dynamic table ublend SQL Server ASP 1 June 1st, 2007 08:09 AM
help writing dynamic form data to dynamic table ublend Classic ASP Professional 1 June 1st, 2007 08:08 AM
How to dynamic display the content of the table? myhrvod Pro Java 0 August 3rd, 2006 12:42 AM
Make IE use fi resx file smiller ASP.NET 2.0 Professional 1 December 4th, 2005 06:25 AM
Any code for automatically inserting queries of fi gilgalbiblewheel Classic ASP Databases 9 September 4th, 2004 12:12 PM





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