473,473 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Adding attribute to HTML output with XSLT

drhowarddrfine
7,435 Recognized Expert Expert
I have this in an XSLT stylesheet sitting in a browser:
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="name" select="@name" />
  2.      <xsl:variable name="input-type" select="@input" />
  3.      <xsl:value-of select="title" />
  4.       <xsl:for-each select="item">
  5.           <input type="{$input-type}"
  6.            name="{$name}" value="{@value}" />
  7.            <xsl:value-of select="."/>
  8.       </xsl:for-each>
  9.  
This all works fine but I need to have a "checked" attribute conditionally inserted before the closing tag based on xml sent from the server tagged as
Expand|Select|Wrap|Line Numbers
  1. <item value="stuff" checked="checked"></item>
The inserted attribute should be "checked" and not 'checked=""'. I've not worked with my XML stuff for a while and I just can't recall how to do this.
May 10 '10 #1
6 2462
Dormilich
8,658 Recognized Expert Moderator Expert
checked (with no value) is an invalid attribute in XML (therefore XSLT won’t write that in xml mode). either use checked="checked" (where the value is gracefully ignored) or try the html output option (not sure if it works, though).
May 10 '10 #2
drhowarddrfine
7,435 Recognized Expert Expert
The xml comes down as 'checked="checked". I want the output of the xslt to be just "checked". The output is in the xhtml namespace.

EDIT: Oh, but that's XML, too. Have to think this through. I may have had it working without thinking about the standalone "checked".
May 10 '10 #3
jkmyoung
2,057 Recognized Expert Top Contributor
checked="true" or checked="" won't work for you?
Expand|Select|Wrap|Line Numbers
  1. <input ...>
  2.   <xsl:if test="someCondition">
  3.     <xsl:attribute name="checked">checked</xsl:attribute><!-- you can change value inside element if needed -->
  4.   </xsl:if>
  5. </input>
May 10 '10 #4
Dormilich
8,658 Recognized Expert Moderator Expert
checked="true" or checked="" won't work for you?
XHTML requires it to be checked="checked". this goes for all HTML standalone attributes in XHTML.
May 10 '10 #5
drhowarddrfine
7,435 Recognized Expert Expert
Now I know what I was forgetting. I didn't add the closing tag </input>
May 10 '10 #6
Dormilich
8,658 Recognized Expert Moderator Expert
or just use the self closing tag
Expand|Select|Wrap|Line Numbers
  1. <input … />
via
Expand|Select|Wrap|Line Numbers
  1. <xsl:element name="input">
  2.     <!-- further definitions -->
  3. </xsl:element>
May 10 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Don Garrett | last post by:
I have an XML document at the root of a directory tree that contains relative URIs to resources in a directory tree. During XSLT processing, these URI's can be used without any problems to...
3
by: Steffen Beyer | last post by:
Hi, my XSLT processes input documents which use various namespaces. Short example: XML input: <news:foo xmlns:news="http://some.example/news"/>
2
by: jaydog | last post by:
Hello... I'm new to XSL, and I've written a XSLT file that converts a XML file to HTML format. When viewed in a browser, it appears exactly as I would like. However, if I want to look at the...
1
by: RSG | last post by:
Hi, Stupid question: how do I get an XSLT stylesheet to emit a comment into the HTML output file? Obviously this won't work; it's interpreted as a comment in the stylesheet: <template ...>...
4
by: Ian Vaughan | last post by:
Any ideas why I am not getting any results back in my HTML via XSLT from my XML doc. It is not returning any errors just no matches when it should return a value of DATA for SchemeName ?? ...
2
by: Taare | last post by:
Hi, I got <xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD HTML 4.01//EN" doctype-system=" http://www.w3.org/TR/html4/strict.dtd"/> in my XSLT file. This should remove...
3
by: Fredy Muñoz [MCP] | last post by:
Hello there! I have a couple of questions about generating HTML using an XSLT Stylesheet. I use the System.Xml and System.Xml.Xsl namespaces and a XslTransform object to make the...
0
by: jrwarwick | last post by:
I wonder what the performance trade off is between using XSL vs .Net Databinding to produce HTML output. It seems they both do a similar thing and either one could be chosen to solve problems such...
21
by: =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= | last post by:
It is common knowledge that XHTML is better HTML and you can serve XHTML content as HTML. However, the second statement is incorrect, for various reasons; it is enough to say that the HTML...
3
by: Andy Dingley | last post by:
>From a thread over in c.i.w.a.h "RFC: From XHTML to HTML via XSLT" http://groups.google.co.uk/group/comp.infosystems.www.authoring.html/msg/f112c230061ffe86 As is well-known, the XSLT HTML...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.