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

Re: howto convert node set into 2D table

Subject: Re: howto convert node set into 2D table
From: "Sam Carleton" <scarleton@xxxxxxxxxxxxxxxx>
Date: Wed, 4 Jul 2007 12:00:28 -0400
Re:  howto convert node set into 2D table
On 7/4/07, Andrew Welch <andrew.j.welch@xxxxxxxxx> wrote:

> Any thoughts on all my rambling?

It's always _much_ easier to work with sample inputs and required
outputs than ramblings, and someone is more likely to reply to a
concise question which takes at most a few minutes to read.

You win;) Here is where I am at:


The desired output is a table that looks like this:

a:1   b:2   c:3    d:4    f:6
h:8   k:11 nbsp  nbsp nbsp

Here is the input:

<category>
<images>
  <image name="a" display="true">1</image>
  <image name="b" display="true">2</image>
  <image name="c" display="true">3</image>
  <image name="d" display="true">4</image>
  <image name="e" display="false">5</image>
  <image name="f" display="true">6</image>
  <image name="g" display="false">7</image>
  <image name="h" display="true">8</image>
  <image name="i" display="false">9</image>
  <image name="j" display="false">10</image>
  <image name="k" display="true">11</image>
</images>
</category>

I have most of the XSLT worked out, I just cannot figure out how to
process the node set in the $imageNodes variable:

<xsl:template match="images">
   <table border="3">

   <xsl:variable name="imageNodes">
     <xsl:apply-templates/>
   </xsl:variable>

<!-- The following line does not work, even though the $imageNodes
contains a node set of image nodes. -->
     <xsl:for-each select="$imageNodes/image[position() mod 5 = 1]">
       <tr>
         <xsl:for-each select=".|following-sibling::image[position() &lt; 5]">
           <td>
             <xsl:value-of select="concat(@name,':',.)"/>
           </td>
         </xsl:for-each>
         <xsl:call-template name="gen_blank_table_col">
           <xsl:with-param name="col_num">
             <xsl:value-of select="5 -
(count(.|following-sibling::image[position() &lt; 5]))"/>
           </xsl:with-param>
         </xsl:call-template>
       </tr>
     </xsl:for-each>

   </table>
 </xsl:template>

 <xsl:template match="image[@display='true']">
   <xsl:copy-of select="."/>
 </xsl:template>

 <xsl:template match="image[@display='false']">
 </xsl:template>

 <!-- =======================================================================
-->
 <!-- This template is used to generate blank table col.-->
 <!--=======================================================================
-->
 <xsl:template name="gen_blank_table_col">
   <xsl:param name="col_num"/>
   <xsl:if test="$col_num > 0">
     <td><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td>
     <xsl:call-template name="gen_blank_table_col">
       <xsl:with-param name="col_num">
         <xsl:value-of select="$col_num - 1"/>
       </xsl:with-param>
     </xsl:call-template>
   </xsl:if>
 </xsl:template>

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.