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 August 16th, 2005, 07:19 AM
Authorized User
 
Join Date: Jul 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default changing attribute value in xslt

Hi All,


edit.xslt:

<xsl:template name="tablerowedit">
        <xsl:for-each select="Field">
            <xsl:variable name="value">
                <xsl:value-of select="."/>
            </xsl:variable>
            <xsl:variable name="name">
                <xsl:value-of select="@name"/>
            </xsl:variable>
            <xsl:variable name="type">
                <xsl:value-of select="/Database/Entries/Table/Header/Field[@name=$name]/@type"/>
            </xsl:variable>
            <xsl:variable name="edittype">
                <xsl:value-of select="/Database/Entries/Table/Header/Field[@name=$name]/@edittype"/>
            </xsl:variable> <xsl:variable name="keyfield">
                <xsl:value-of select="/Database/Entries/Table/Header/Field[@name=$name]/@keyfield"/>
            </xsl:variable>
            <xsl:if test="$edittype!='hidden'">
                <xsl:variable name="description">
                    <xsl:value-of select="/Database/Entries/Table/Header/Field[@name=$name]/@description"/>
                </xsl:variable>
                <xsl:variable name="enumeration">
                    <xsl:value-of select="/Database/Entries/Table/Header/Field[@name=$name]/@enumeration"/>
                </xsl:variable>
                <xsl:variable name="hreflink">
                    <xsl:value-of select="/Database/Entries/Table/Header/Field[@name=$name]/@listmodule"/>
                </xsl:variable>

                <xsl:variable name="minval">
                    <xsl:value-of select="/Database/Entries/Table/Header/Field[@name=$name]/@minval"/>
                </xsl:variable>

                <xsl:variable name="maxval">
                    <xsl:value-of select="/Database/Entries/Table/Header/Field[@name=$name]/@maxval"/>
                </xsl:variable>

                <xsl:variable name="required">
                    <xsl:value-of select="/Database/Entries/Table/Header/Field[@name=$name]/@required"/>
                </xsl:variable>

                <xsl:variable name="pos">
                    <xsl:value-of select="position()"/>
                </xsl:variable>

                <xsl:variable name="index">
                    <xsl:value-of select="count(/Database/Entries/Table/Header/Field[position() &lt; $pos and @edittype!='hidden'] )"/>
                </xsl:variable>

                <xsl:variable name="background">
                    <xsl:choose>
                        <xsl:when test="($index mod 2) = 1">
                            <xsl:value-of select="'background-color:rgb(239, 239, 239)'"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="'background-color:rgb(220, 220, 220)'"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>

                <tr>
                    <xsl:attribute name="id">
                        <xsl:value-of select="$name"/>
                    </xsl:attribute>
<!--
                    <xsl:attribute name="style">
                        <xsl:value-of select="concat('', 'visibility:visible;', $background, ';height:20px;')"/>
                    </xsl:attribute>
-->
                    <td width="35%" valign="middle">
                        <xsl:if test="/Database/Entries/Table/Header/Field[@name=$name]/@reboot='true'">
                            <a style="color:red">*</a>
                        </xsl:if>
                        <xsl:choose>
                            <xsl:when test="string-length(normalize-space($description))>0">
                                <xsl:value-of select="$description"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="@name"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </td>
                    <td valign="middle">
                        <xsl:call-template name="icon">
                            <xsl:with-param name="name" select="$name"/>
                        </xsl:call-template>
                        <xsl:choose>
                            <xsl:when test="/Database/hreflink[@name=$name]/@partitioner='' and count(/Database/hreflink[@name=$name]/Field)>0 and string-length(normalize-space($hreflink))>0">
                                <xsl:call-template name="listmodule">
                                    <xsl:with-param name="name" select="$name"/>
                                    <xsl:with-param name="value" select="$value"/>
                                    <xsl:with-param name="keyfield" select="$keyfield"/>
                                    <xsl:with-param name="submit" select="$submit"/>
                                </xsl:call-template>
                            </xsl:when>
                            <xsl:when test="/Database/hreflink[@name=$name]/@partitioner!='' and count(/Database/hreflink[@name=$name]/Field)>0 and string-length(normalize-space($hreflink))>0">
                                <xsl:call-template name="partition">
                                    <xsl:with-param name="name" select="$name"/>
                                    <xsl:with-param name="value" select="$value"/>
                                    <xsl:with-param name="keyfield" select="$keyfield"/>
                                    <xsl:with-param name="submit" select="$submit"/>
                                </xsl:call-template>
                            </xsl:when>
                            <xsl:when test="count(/Database/hreflink[@name=$name]/Field)=0 and string-length(normalize-space($hreflink))>0">
                                <xsl:value-of select="concat('No Data for ', ' ',$description)"/>
                            </xsl:when>

                            <xsl:otherwise>

                                <xsl:variable name="enable">
                                    <xsl:value-of select="'true'"/>
                                </xsl:variable>

                                <xsl:variable name="fieldEdittype">
                                    <xsl:choose>
                                        <xsl:when test="/Database/Entries/Table/@name='station' and $name='IpAddress'">
                                            <xsl:value-of select="'read-only'"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="$edittype"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:variable>

                                <xsl:call-template name="gettype">
                                    <xsl:with-param name="enable" select="$enable"/>
                                    <xsl:with-param name="fieldname" select="@name"/>
                                    <xsl:with-param name="fieldval" select="."/>
                                    <xsl:with-param name="type" select="$type"/>
                                    <xsl:with-param name="edittype" select="$fieldEdittype"/>
                                    <xsl:with-param name="keyfield" select="$keyfield"/>
                                    <xsl:with-param name="submit" select="'false'"/>
                                    <xsl:with-param name="enumeration" select="$enumeration"/>
                                </xsl:call-template>
                            </xsl:otherwise>
                        </xsl:choose>
                    </td>
                </tr>

                <xsl:variable name="fieldval">
                    <xsl:choose>
                        <xsl:when test="/Database/hreflink[@name=$name]/Field">
                            <xsl:value-of select="/Database/hreflink[@name=$name]/Field/."/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="."/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>

                <xsl:call-template name="unique">
                    <xsl:with-param name="name" select="$name"/>
                    <xsl:with-param name="enumeration" select="$enumeration"/>
                    <xsl:with-param name="hreflink" select="$hreflink"/>
                    <xsl:with-param name="fieldval" select="."/>
                    <xsl:with-param name="type" select="$type"/>
                    <xsl:with-param name="edittype" select="$edittype"/>
                    <xsl:with-param name="keyfield" select="$keyfield"/>
                    <xsl:with-param name="minval" select="$minval"/>
                    <xsl:with-param name="maxval" select="$maxval"/>
                    <xsl:with-param name="required" select="$required"/>
                </xsl:call-template>

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






in the above code i want to assign a value for the edittype when particular field attribute is matched otherwise it has to take values from database.xml

in the database.xml

i have


<databse>
   <entries>
       <table>
          <header>
               <field name="serialnumber" edittype="read-write"/>

               <field name="a" edittype="readwrite"/>
                <field name="b" edittype="read-write"/>
                etc
          </header>
        </table>
    </entries>
  </database>



please help me out.






 
Old August 16th, 2005, 08:07 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Don't do this:

<xsl:variable name="pos">
     <xsl:value-of select="position()"/>
</xsl:variable>

Do this:

<xsl:variable name="pos" select="position()"/>

In the first case you are creating a result tree fragment: a heavyweight data structure with a root node and a text node containing the value of position() converted from a number to a string. In the second case the variable is a simple number. I can't understand why so many people make this mistake (perhaps they are paid by how many lines of code they write?)

I can't help you with the question you asked, I'm afraid - I'm not sure what you're trying to achieve. Please simplify it to show the essence of the difficulty.






Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in XSLT with "//" in attribute value kaps77 XSLT 3 November 6th, 2007 10:57 AM
changing attribute value in MS word cse.sandeep XSLT 4 June 7th, 2007 05:54 AM
XSLT, add attribute ik XSLT 6 August 22nd, 2006 11:03 AM
Changing the attribute values in XSLT NEO1976 XSLT 5 May 23rd, 2006 03:53 AM
changing the value of attribute name stone XSLT 1 October 21st, 2005 06:35 AM





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