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 December 12th, 2007, 02:32 PM
Registered User
 
Join Date: Nov 2007
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?

 
Old December 12th, 2007, 06:52 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old December 14th, 2007, 01:51 PM
Registered User
 
Join Date: Nov 2007
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?

 
Old December 14th, 2007, 02:00 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old December 14th, 2007, 02:04 PM
Friend of Wrox
 
Join Date: Nov 2007
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.






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





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