-
Conditional attribute in xsl:element
Hi,
I'm trying to generate a <body> tag that will have a couple of attributes that will only be needed based on the presence of a variable.
This is what I have:
<xsl:element name="body">
<xsl:variable name="jsString" select="$sourcingInsertJavascriptString"/>
<xsl:attribute name="class">body</xsl:attribute>
<xsl:if test="$jsString">
<xsl:attribute name="onclick">dynOutline()</xsl:attribute>
<xsl:attribute name="language">Javascript1.2</xsl:attribute>
</xsl:if>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<xsl:apply-templates select="@*|node()" />
</table>
</xsl:element>
This is not working for me. I am using $sourcingInsertJavascriptString variable elsewhere and it works correctly. Is this conditional adding of attributes to the body tag possible like this? I only want the onclick attribute added to the body tag if that variable is present.
Thanks!
Gordie
-
This looks fine to me. There is nothing wrong with creating attributes conditionally as long as they are created before nested elements, which they are.
Have you tried debugging your XSLT to check the value of 'sourcingInsertJavascriptString'!?
As this would suggest that this is the cause of the attributes not being present in your output.
-
not enough information about the xml file to see the error
Please show the original xml
-
 Originally Posted by xml-looser
not enough information about the xml file to see the error
Please show the original xml
You do not need the XML to see that the issue lies within the XSLT.
-
there are so many opportunities where the error could be
namespace
a forgotten bracket
your new variable even though there is already a
<xsl:variable name="jsString" select="$sourcingInsertJavascriptString"/>
and your choice other nodes
<xsl:apply-templates select="@*|node()" />
if you are not xml I show can not help you
you do not need to use original values only example values
I still try to understand that you want to do
I suspect you have a variable defined param
<xsl aram name="sourcingInsertJavascriptString" select="true()"/>
here is only when true () is set
this is param then be a toplevel element
all other values not go
it is nonsense of the step between
<xsl:variable name="jsString" select="$sourcingInsertJavascriptString"/>
then the same here
<xsl:if test="$sourcingInsertJavascriptString">
otherwise it will only consider sourcing insert contains a javascript string value in $sourcingInsertJavascriptString
such
<xsl:variable name="jsString" select="contains($sourcingInsertJavascriptString,'//javascript')"/>
which makes a string a bool value
and param with value
<xsl aram name="sourcingInsertJavascriptString" select=" '//javascript' "/>
This is forum is to volunteer base
not to earn money
sorry for my bad english
Similar Threads
-
Replies: 1
Last Post: 02-06-2008, 10:18 AM
-
Replies: 1
Last Post: 10-31-2005, 02:57 PM
-
Replies: 1
Last Post: 04-26-2001, 03:20 AM
-
By Noga Atsil in forum XML
Replies: 1
Last Post: 11-21-2000, 01:04 PM
-
By Larry Rebich in forum vb.announcements
Replies: 0
Last Post: 05-22-2000, 12:49 AM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|