By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,016 Members | 2,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,016 IT Pros & Developers. It's quick & easy.

System.Xml.Xsl.Transform -vs- xhtml???

P: n/a
I'm trying to output valid xhtml 1.0 transitional with xslt -- my question
is when dealing with elements that have self-closing tags such as <img />
and <input />...

I'm getting closing tags on these elements that should have a self-closing
tag like this:
<img src="/images/img.jpg" alt="alt text"></img>
should be:
<img src="/images/img.jpg" alt="alt text" />

Is this something wrong with my xsl? or is this an issue with the
System.Xml.Xsl.Transform method???

here's an example:
<xsl:element name="img">
<xsl:attribute name="src"><xsl:value-of select="$folder"
/>/ui/img/<xsl:value-of select="Root/Portal/global/company_logo/@src"
/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of
select="Root/Portal/global/company_logo/@alt" /></xsl:attribute>
</xsl:element>

the output result is:
<img src="/test/ui/img/logo.png" alt="Logo Image"></img>

I've tried various settings in the xsl:output as well, here is the current:
<xsl:output method="xml" media-type="text/html" omit-xml-declaration="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
encoding="UTF-8" indent="yes" />
the complete xsl doc is at:
http://clients.humaniz.net/xsl/sitemain.xsl
thanks!!!
mo
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hello!
here's an example:
<xsl:element name="img">
<xsl:attribute name="src"><xsl:value-of select="$folder"
/>/ui/img/<xsl:value-of select="Root/Portal/global/company_logo/@src"
/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of
select="Root/Portal/global/company_logo/@alt" /></xsl:attribute>
</xsl:element>


Maybe it helps if you use the inline-Attribute-syntax:

<img src="{$folder}/ui/img/{Root/Portal/global/company_logo/@src}
alt="{Root/Portal/global/company_logo/@alt}" />

(Visual Studio may show you errors like '{ is not valid in NAMEs' - just
ignore that.)
--
Pascal Schmitt
Nov 12 '05 #2

P: n/a


Martin Olson wrote:
I'm trying to output valid xhtml 1.0 transitional with xslt -- my question
is when dealing with elements that have self-closing tags such as <img />
and <input />...

I'm getting closing tags on these elements that should have a self-closing
tag like this:
<img src="/images/img.jpg" alt="alt text"></img>
should be:
<img src="/images/img.jpg" alt="alt text" />


For XML
<img />
and
<img/>
and
<img></img>
are equivalent ways of marking up an empty element with the name 'img'.
Your problem is that you do not only want to create XHTML and parse it
with an XHTML parser where <img></img> is fine but you seem to want to
send XHTML to HTML browsers like IE as content type text/html where the
XHTML is not parsed by an XML parser but by the browsers tag soup parser
that implements SGML with error correction and not XML.
So the problem is not with your stylesheet or your XSLT processor but
rather with your approach, see
<http://www.w3.org/TR/xhtml1/#guidelines>
<http://www.hixie.ch/advocacy/xhtml>

As long as you want to serve text/html consider using the proper
document type for that namely HTML 4.01 and not XHTML 1.0.

If you insist on serving XHTML 1.0 as text/html then you have to ensure
that your XHTML is backwards compatible with HTML and XSLT 1.0 has no
tools to achieve that so you need a custom serializer for the result
tree of your XSLT transformation. One solution for that can be found here:
<http://schneegans.de/asp.net/xhtmltextwriter/>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #3

P: n/a
Thank you both very much for your help.

I'll be using the inline attribute syntax on this project.

The info at: http://www.w3.org/TR/xhtml1/#guidelines is very helpful and
thanks for giving me a clue!

thanks!
mo
"Martin Olson" <pl****@no-spam.thankyou> wrote in message
news:uq**************@TK2MSFTNGP14.phx.gbl...
I'm trying to output valid xhtml 1.0 transitional with xslt -- my question
is when dealing with elements that have self-closing tags such as <img />
and <input />...

I'm getting closing tags on these elements that should have a self-closing
tag like this:
<img src="/images/img.jpg" alt="alt text"></img>
should be:
<img src="/images/img.jpg" alt="alt text" />

Is this something wrong with my xsl? or is this an issue with the
System.Xml.Xsl.Transform method???

here's an example:
<xsl:element name="img">
<xsl:attribute name="src"><xsl:value-of select="$folder"
/>/ui/img/<xsl:value-of select="Root/Portal/global/company_logo/@src"
/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of
select="Root/Portal/global/company_logo/@alt" /></xsl:attribute>
</xsl:element>

the output result is:
<img src="/test/ui/img/logo.png" alt="Logo Image"></img>

I've tried various settings in the xsl:output as well, here is the
current:
<xsl:output method="xml" media-type="text/html" omit-xml-declaration="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
encoding="UTF-8" indent="yes" />
the complete xsl doc is at:
http://clients.humaniz.net/xsl/sitemain.xsl
thanks!!!
mo

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.