Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 12th, 2007, 02:32 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default xhtml input tag not rendered correctly by xslt

When I transform xml into xhtml using my code below, it leaves a carriage return between the opening and closing <input> tags:

XSLT:

<input type="radio" name="abc">
  <xsl:attribute name="value">
    <xsl:value-of select="@ActivityCode"/>
  </xsl:attribute>
  <xsl:attribute name="id">
    <xsl:value-of select="@ActivityCode"/>
  </xsl:attribute>
</input>
<label>
  <xsl:attribute name="for">
    <xsl:value-of select="@ActivityCode"/>
  </xsl:attribute>
  <xsl:value-of select="@ProgramName"/>
</label>

XHTML Rendered:

<input type="radio" name="abc" value="a1" id="a1">
</input>
<label for="a1">111</label>
<br />
<input type="radio" name="abc" value="a2" id="a2">
</input>
<label for="a2">222</label>
<br />
etc...

Ideally I want to get rid of the closing input tag and make it a self-closing input tag like this: <input />. But this doesn't seem to be doable, so I want to at least get rid of the carriage return to be valid xhtml. Does anyone know how to do this?

Reply With Quote
  #2 (permalink)  
Old December 12th, 2007, 06:52 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSLT 2.0 has an output method="xhtml".

You don't say what output method you are using or which XSLT version you are using.

Also, your output appears to have a single space as the content of the input element, but there's nothing in your stylesheet that could produce that space.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old December 14th, 2007, 01:51 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm using XSLT 1.0. My output method is XML but I'm producing XHTML:

<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

Can I still generate the valid <input> with XSLT 1.0?

Reply With Quote
  #4 (permalink)  
Old December 14th, 2007, 02:00 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you're stuck with XSLT 1.0 then my advice would be to produce two different serializations of the output: an HTML serialization for sending to the browser, and an XML serialization for sending to anyone else. There are no mechanisms in XSLT 1.0 to serialize using the special compromise conventions defined in the XHTML specification, for example forcing an empty paragraph to be output as <p></p>.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old December 14th, 2007, 02:04 PM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Which XSLT processor do you use? I could imagine that you get
  <input ...></input>
or
  <input/>
both of which are not good for XHTML sent to text/html browsers but I don't understand why you would get
  <input ...>
  </input>
unless there is something wrong with the indentation/serialization.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT for parsing XHTML Form shahbhat XSLT 6 August 26th, 2008 06:22 PM
xslt -> xhtml validation rahulsk1947 XSLT 3 May 17th, 2007 02:54 AM
producing XHTML from XSLT holdmykidney XSLT 1 August 24th, 2004 09:00 AM
Converting XHTML to Word ML using XSLT debsoft XSLT 1 July 7th, 2004 04:36 AM
XHTML to Word ML using XSLT debsoft XSLT 0 June 26th, 2004 04:53 AM



All times are GMT -4. The time now is 07:11 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.