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 November 14th, 2005, 08:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default Use variables or other construct?

Not too good with all the constructs yet, so I have a small issue with the following piece of XSLT...
Code:
<xsl:if test="count(references/reference) > 0">
    <td class="thumb" rowspan="2">
        <a href="{@full}" target="blank">
            <img class="thumb" src="{@thumb}" alt="{languages/this/string[@name='thumbalt']}" />
        </a>
    </td>
</xsl:if>
<xsl:if test="count(references/reference) = 0">
    <td class="thumb" rowspan="1">
        <a href="{@full}" target="blank">
            <img class="thumb" src="{@thumb}" alt="{languages/this/string[@name='thumbalt']}" />
        </a>
    </td>
</xsl:if>
Clearly, it is not pretty, since there is a lot of redundant HTML. The only difference is the value of the rowspan attribute. I cannot find a way to get the same result as the above code with less redundant code.

Can I use variables somehow? Tried but could not override already assigned variables. I would have liked to be able to do something like this instead...
Code:
<xsl:variable name="spaning" select="1" />
<xsl:if test="count(references/reference) > 0">
    <xsl:variable name="spaning" select="2" />
</xsl:if>
<td class="thumb" rowspan="{$spanning}">
    <a href="{@full}" target="blank">
        <img class="thumb" src="{@thumb}" alt="{languages/this/string[@name='thumbalt']}" />
    </a>
</td>
Is there som construct I should learn about to solve problems like this?

Thanks, Jacob.
__________________
Danish audio books for download at http://www.lytenbog.dk (Danske lydbøger til download).
 
Old November 14th, 2005, 09:06 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In 2.0

<xsl:variable name="rowspan"
select="if (references/reference) then 2 else 1"/>

In 1.0

<xsl:variable name="rowspan">
  <xsl:choose>
    <xsl:when test="references/reference">2</xsl:when>
    <xsl:otherwise>1</xsl:otherwise>
  </xsl:choose>
</xsl:variable>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 15th, 2005, 06:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael Kay... You seem to know it all. You information was very interesting; i.e. that it is possible within a variable scope to define conditional evaluation. Neat, though I am a little puzzled about 1.0 and 2.0.

The XSLT transformation, which I am doing is done through C# for a private web application and using the XslTransform class. The transformation is thus server-side and must therefore depend on which version the hosting server supports, right?

Does the version of XSLT follow the .NET version number or is that just a coincidence?

Thanks again, Jacob.
 
Old November 15th, 2005, 07:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you're using the XSLT processor that comes with .NET then it only supports XSLT version 1.0.

XSLT has nothing to do with Microsoft, so the version numbers are unrelated.

XSLT 2.0 has just reached Candidate Recommendation status so there are relatively few implementations yet: the one that most people are using is my own Saxon product. There's a version of this that's been ported to .NET but people use the Java version.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 15th, 2005, 08:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, I see! Therefore, if I depend on a low-price web hotel for my private project, then I must focus on the 1.0 version, however, probably worth keeping an eye on 2.0.

I have come across Saxon lots of time when searching the internet, but I guess not suited for my small pet-project. Looks very cool.

Thanks for now, Jacob.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Construct checkbox with Javascript BananaJim Javascript How-To 4 April 30th, 2012 02:32 AM
Construct a SQL Select Statement ricespn Beginning VB 6 1 May 28th, 2007 07:57 AM
Using Mapper with Transform - How to construct msg anuphshah Biztalk 0 August 16th, 2006 06:44 AM
changing pixel color in if/then construct rharris VB.NET 2002/2003 Basics 1 June 19th, 2005 09:12 AM





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