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 December 20th, 2003, 07:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Quote:
quote:Originally posted by btado
 Wow!

You have out done yourself! Thank you immensely for all of your help.

I am wondering if you would know how to choose which columns of data that you want to display. I don't want to display all of the columns of data, just a few of them.

I could write a stylesheet to transform the xml to another xml file that only has the fields that I want...but could this stylesheet be adapted to be able to choose which fields you want to display?

Again, thanks for your help!!!!


I think the simplest solution is to perform two passes(and this approach requires minimum changes to the original code, leaving the logic untouched):

a) Get the subtree, which will represent the table. For example, if your XML document is
Code:
<doc>
  <part1>
    ...
  </part1>
  <table>
   <rows>
    <row>
     <item1/>   
     <item2/>
     <item3/>
     <itemX/>   
     <item4/>
     <itemX/>
     <item5/>
     ...
    </row>
    ... 
   </rows> 
  </table>
</doc>
then you can write a set of templates to get the structure I mentioned in my previous post. It can be done like this:

Code:
<xsl:variable name="table-structure">
 <xsl:apply-templates select="/doc/table" mode="fetch-table"/>
<xsl:variable>

<xsl:template match="doc/table" mode="fetch-table">
 
</xsl:template>
b) Once you get the structure, you need to properly set the value of the variable "all-items":
Code:
<xsl:variable name="all-items" select="exsl:node-set($all-items)/*/*"/>
Here "exsl" namespace prefix must be bound to the namespace URI "http://exslt.org/common" and properly declared.


Acting this way the table-renderer can be used as a separate module. It perhaps needs some optimization to make it fully independent.

Regards,
Armen
 
Old December 21st, 2003, 08:35 PM
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to btado
Default

Armen,

Again, thanks for your help. I am unclear on the namespace for exslt. Here are my declarations:
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:exsl="http://exslt.org/common"
                extension-element-prefixes="exsl">

<xsl:import href="exsl.xsl" />

The stylesheet is unable to find the object specified for <xsl:import href="exsl.xsl" /> and when I leave that out, I get the following error: the namespace http://exslt.org/common does not contain any functions.

Again, thanks!!

 
Old December 22nd, 2003, 01:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Quote:
quote:Originally posted by btado
 Armen,

Again, thanks for your help. I am unclear on the namespace for exslt. Here are my declarations:
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:exsl="http://exslt.org/common"
                extension-element-prefixes="exsl">

<xsl:import href="exsl.xsl" />

The stylesheet is unable to find the object specified for <xsl:import href="exsl.xsl" /> and when I leave that out, I get the following error: the namespace http://exslt.org/common does not contain any functions.

Again, thanks!!

You don't need to include any stylesheet. Your processor probably supports something like node-set() function, which is defined in EXSLT(and hence, you need just to declare the namespace like you did). Look at your XSLT processor documentation. If you are using Saxon, you can just set the version="1.1" in the XML declaration of the stylesheet, and the RTF->nodeset conversion will be done for you implicitly(that is, Saxon will recognize that the variable contains RTF and will perform the conversion without writing exslt:node-set(...)). If not, you have to use that function: mostly all well-known processors implement EXSLT.

Regards,
Armen
 
Old December 23rd, 2003, 06:45 PM
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to btado
Default

Armen,

I was finally able to make your suggestions work. Thanks for your help.
I GREATLY appreciate all of your advice.

Tad

 
Old December 24th, 2003, 01:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Quote:
quote:Originally posted by btado
 Armen,

I was finally able to make your suggestions work. Thanks for your help.
I GREATLY appreciate all of your advice.

Tad

Happy to help, Tad. Unfortunately I had not enough time to describe these "adaptation" steps in more details, however it's great that you've done.
XSLT is strong enough: it's, after all, a functional programming language(as Dimitre Novatchev has shown)! :)

Regards,
Armen
 
Old December 24th, 2003, 11:52 AM
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to btado
Default

Armen,

One more question:
For each of the cells with grey background, I'd like to add a span tag with an onclick event which would carry the @id record value.
When I add the span tag to my apply-template section, the values are not passed to the resulting table.
Any suggestions?

Thanks,

Tad

 
Old December 24th, 2003, 12:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

There are actually 3 places where the background is grey:
1. In the header. You don't need to change anything for this case.
2. In non-empty cells which are the first:
Code:
...
<xsl:template name="put-item">
        <xsl:param name="internal-col-idx" select="0"/>
        <xsl:param name="r"/>
        <xsl:param name="c"/>
        <xsl:if test="$c &lt;= $n-big-cols">
            <xsl:variable name="curr-el" select="$all-items[($c - 1) * $n-rows + $r]/*[$internal-col-idx + 1]"/>
            <xsl:choose>
                <xsl:when test="not($curr-el)">
                    <xsl:call-template name="fill-gap">
                        <xsl:with-param name="cnt" select="$n-fields"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                    <td>
                       <!-- OLD VARIANT START
                        <xsl:if test="not($curr-el/preceding-sibling::*)">
                            <xsl:attribute name="bgcolor"><xsl:value-of select="$first-col-color"/></xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="$curr-el"/>
                         OLD VARIANT END -->

                      <xsl:choose>  
                        <xsl:when test="not($curr-el/preceding-sibling::*)">
                            <xsl:attribute name="bgcolor"><xsl:value-of select="$first-col-color"/></xsl:attribute>
                        <span> 
                           <xsl:value-of select="$curr-el"/>
                        </span>
                        </xsl:when>
                        <xsl:otherwise> 
                            <xsl:value-of select="$curr-el"/>
                        <xsl:otherwise>
                      </xsl:choose>  

                    </td>
...
3. In empty cells which are the first(in the "fill-gap" template body). You don't need to change anything for this case.


Regards,
Armen





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT 1.0: Looping through nodes kwilliams XSLT 4 December 1st, 2008 06:21 PM
XSLT and tables surgeon XSLT 1 July 3rd, 2005 03:36 AM
XSLT Looping Logic - Very Urgent ujayaraman XSLT 2 March 3rd, 2005 10:42 AM
looping through 2 tables Hudson40 Access VBA 2 February 4th, 2005 01:12 PM
xslt looping richjo100 XSLT 6 September 23rd, 2004 11:20 AM





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