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 21st, 2006, 04:10 PM
ik ik is offline
Authorized User
 
Join Date: Aug 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT, add attribute

Plase, why cannot I add attribute ?
line : <xsl:attribute name="onclick">__Goto(<xsl:value-of select="@id"/>, <xsl:value-of select="ancestor::cat[1]/@id"/>);</xsl:attribute>

when I make transformation, there is no OnClick Attribute.



<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>

<xsl:param name="catId"/>
<xsl:param name="subCatId"/>

<xsl:template match="/">

<TABLE cellpadding="0" cellspacing="0" border="0" class="catMenu">
<xsl:for-each select="//cats/cat">
<TR onmouseover="__MOn(this);" onmouseout="__MOff(this);">
<TD class="catName">
<xsl:attribute name="onclick">__Show(<xsl:value-of select="@id"/>);</xsl:attribute>
<xsl:value-of select="@name"/>
</TD>
</TR>

<TR class="sCatContainerH">
<xsl:if test="@id=$catId">
<xsl:attribute name="class">sCatContainerV</xsl:attribute>
</xsl:if>
<xsl:attribute name="id">cat<xsl:value-of select="@id"/></xsl:attribute>
<TD>
    <TABLE class="subCats" cellpadding="0" cellspacing="0" border="0" width="100%">
    <TR>
    <TD class="sCatName" onmouseover="__MOn(this);" onmouseout="__MOff(this);">Today events
    <xsl:attribute name="id">catProba</xsl:attribute>
    <xsl:attribute name="onclick">__Goto(0, <xsl:value-of select="ancestor::cat[1]/@id"/>);</xsl:attribute>
    </TD></TR>
    <xsl:for-each select="subCat">

        <TR>
        <TD class="sCatName" onmouseover="__MOn(this);" onmouseout="__MOff(this);">
        <xsl:attribute name="onclick">__Goto(<xsl:value-of select="@id"/>, <xsl:value-of select="ancestor::cat[1]/@id"/>);</xsl:attribute>
        <xsl:if test="@id=$subCatId"><xsl:attribute name="style">font-weight:bold</xsl:attribute></xsl:if>
        <xsl:value-of select="."/>
        </TD>
        </TR>
    </xsl:for-each>
    </TABLE>
</TD>
</TR>
</xsl:for-each>
</TABLE>

</xsl:template>

</xsl:stylesheet>
 
Old August 22nd, 2006, 01:33 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you show a sample of the source XML?

--

Joe (Microsoft MVP - XML)
 
Old August 22nd, 2006, 02:27 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Presumably your stylesheet doesn't find what it's looking for in the input document. Without seeing the input document, it's impossible to debug it for you.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 22nd, 2006, 04:14 AM
ik ik is offline
Authorized User
 
Join Date: Aug 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default


 >>Presumably your stylesheet doesn't find what it's looking for in
 >>the input document. Without seeing the input document, it's
 >>impossible to debug it for you.

I made amistake in my privious email : I din not want to add two attributes, only one (bold)
<xsl:attribute name="id">catProba</xsl:attribute>
<xsl:attribute name="onclick">__Goto(0, <xsl:value-of select="ancestor::cat[1]/@id"/>);</xsl:attribute>

But if I try to add following :
<xsl:attribute name="onclick">__Goto(0,9);</xsl:attribute>
or
<xsl:attribute name="id">catProba</xsl:attribute>
It doesn't work too.
 
Old August 22nd, 2006, 07:22 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

As I say, I can't debug it with seeing the source document. Showing me different code from the code that you were actually running also makes it a wee bit more difficult to find your bugs.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 22nd, 2006, 10:51 AM
ik ik is offline
Authorized User
 
Join Date: Aug 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm sending xml and xslt :

<?xml version="1.0" encoding="UTF-8"?>
<cats>
<cat id="1" name="American Football">
<subCat id="1">CFL</subCat>
<subCat id="2">NFL</subCat>
</cat>
<cat id="2" name="Baseball">
<subCat id="3">Japanese Baseball</subCat>
<subCat id="4">MLB</subCat>
<subCat id="5">World Baseball Classics</subCat>
</cat>
</cats>



<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>

<xsl:param name="catId"/>
<xsl:param name="subCatId"/>

<xsl:template match="/">

<TABLE cellpadding="0" cellspacing="0" border="0" class="catMenu">
<xsl:for-each select="//cats/cat">
<TR onmouseover="__MOn(this);" onmouseout="__MOff(this);">
<TD class="catName">
<xsl:attribute name="onclick">__Show(<xsl:value-of select="@id"/>);</xsl:attribute>
<xsl:value-of select="@name"/>
</TD>
</TR>

<TR class="sCatContainerH">
<xsl:if test="@id=$catId">
<xsl:attribute name="class">sCatContainerV</xsl:attribute>
</xsl:if>
<xsl:attribute name="id">cat<xsl:value-of select="@id"/></xsl:attribute>
<TD>
    <TABLE class="subCats" cellpadding="0" cellspacing="0" border="0" width="100%">
    <TR>
    <TD class="sCatName" onmouseover="__MOn(this);" onmouseout="__MOff(this);">Today events
     <xsl:attribute name="onclick">__Goto(<xsl:value-of select="@id"/>, <xsl:value-of select="ancestor::cat[1]/@id"/>);</xsl:attribute>
    </TD></TR>
    <xsl:for-each select="subCat">

        <TR>
        <TD class="sCatName" onmouseover="__MOn(this);" onmouseout="__MOff(this);">
        <xsl:attribute name="onclick">__Goto(<xsl:value-of select="@id"/>, <xsl:value-of select="ancestor::cat[1]/@id"/>);</xsl:attribute>
        <xsl:if test="@id=$subCatId"><xsl:attribute name="style">font-weight:bold</xsl:attribute></xsl:if>
        <xsl:value-of select="."/>
        </TD>
        </TR>
    </xsl:for-each>
    </TABLE>
</TD>
</TR>
</xsl:for-each>
</TABLE>

</xsl:template>

</xsl:stylesheet>
 
Old August 22nd, 2006, 11:03 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Saxon gives this error message:

Error on line 21 of file:/c:/temp/test.xsl:
  XTDE0410: Cannot create an attribute node after creating a child of the containing element

XSLT 1.0 processors are allowed to ignore this error and "recover" by ignoring the xsl:attribute instruction. I expect you are using such a processor.

What's wrong is this:

    <TD class="sCatName">
       Today events
       <xsl:attribute name="onclick">__Goto...;</xsl:attribute>
    </TD>

where you create the child element of the TD before creating its attribute.

Incidentally, I would have spotted this far earlier if you had taken the trouble to lay out your code more neatly.

This becomes a hard error in XSLT 2.0 that all processors must report. Saxon actually detects this particular instance at compile time.

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
How to add an attribute to each element bartnowa XSLT 3 November 8th, 2007 12:12 PM
How to add attribute to unbounded element 2BOrNot2B XML 4 January 16th, 2007 03:42 PM
Attribute.add and Refresh Problem Ardvisoor ASP.NET 2.0 Professional 3 July 25th, 2006 12:10 PM
How to add an attribute crossedge XSLT 5 March 16th, 2006 06:31 AM
Add an attribute to existing table peter_budo SQL Language 9 April 24th, 2005 01:35 PM





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