[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to Process when Row data could be either elements

Subject: How to Process when Row data could be either elements or attributes
From: Imrran Wahid <devguy2003@xxxxxxxxx>
Date: Thu, 20 Mar 2003 13:09:53 -0800 (PST)
row data
I have come upon another stumper and once again I hope
one of the more experienced minds can help as you have
done in the past.

I am creating tables from an xml that could have the
column data in the rows represented either as elements
or as attributes. I have solved the problem when the
data is in elements. Now I want so that it handles the
data when it is in attributes. I do not want to use
separate stylesheets. So I tried to incorporate the
solution to the second part into the working solution
to the first part.

eg. of xml to transform - row data in elements:

<fruits>
  <oranges>
    <orange>
      <type>navel</type>
      <origin>Uruguay</origin>
    </orange>
    <orange>
      <type>temple</type>
      <origin>Brazil</origin>
    </orange>
  </oranges>
  <apples>...
  <apples>
</fruits>

eg of xml to transform - row data in attributes:

<fruits>
  <oranges>
    <orange type="navel" origin="Uruguay"/>
    <orange type="temple" origin="Brazil"/>
  </oranges>
  <apples>...
  <apples>
</fruits>

The templates I used to transform when the row data is
in elements are:

<xsl:template match="//Fruits/*[count(./*) &gt; 0]"
mode="regularTable">
    <table>
      <tr>
        <!-- this is the row with the col headings -->
        <xsl:for-each select="./*[1]/*">
          <th><xsl:value-of select="name(.)"/></th>
        </xsl:for-each>
     </tr>
        <xsl:apply-templates select="*"/></table>
</xsl:template>

<xsl:template match="//Fruits/*[count(./*) &gt; 0]/*">
  <tr>
    <xsl:apply-templates select="*"/>
  </tr>
</xsl:template>

<xsl:template match="*">
  <td>
    <xsl:value-of select="normalize-space(text())"/>
  </td>
</xsl:template>

How do I modify these to transform when the row data
is in attributes?

I was only able to get the column headings to
transform properly by making a
change(select="./*[1]/*|./*[1]/@*") in the template as
shown below:

<xsl:template match="//Fruits/*[count(./*) &gt; 0]"
mode="regularTable">
    <table>
      <tr>
        <!-- this is the row with the col headings -->
        <xsl:for-each select="./*[1]/*|./*[1]/@*">
          <th><xsl:value-of select="name(.)"/></th>
        </xsl:for-each>
     </tr>
        <xsl:apply-templates select="*"/></table>
</xsl:template>

I could not get the cell data to populate...whatever i
try doesn't seem to work for me.

Appreciate any help.
Thanks
  


__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.