This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > August 2006 > XSL self-closing tags with xsl:attribute





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author XSL self-closing tags with xsl:attribute
regenesis0@gmail.com

2006-08-24, 10:35 pm

Hey-o. I'm trying to generate HTML transitional code that validates
using XSL. For the most part is is easy- good XML and good XSL
standards produces good html!

However, I have a tiny problem. Images. (And Metatags.) Elements
with just attributes (and thus self-closing.)

So a chunk of xsl like:
<img alt="">
<xsl:choose>
<xsl:when test="$hascustom = 'true'">
<xsl:attribute name="src"><xsl:value-of select="stream_file"
/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="src">default.gif</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</img>

will produce:
<img alt="" src="default.gif"></img>(or somethign much like it.)

....validators dislike this. They want a
<img alt="" src="default.gif"/>
Is there a way to make it produce a self-closing tag?

-Derik

Peter Flynn

2006-08-24, 10:35 pm

regenesis0@XXXXXXXXXX wrote:
> Hey-o. I'm trying to generate HTML transitional code that validates
> using XSL. For the most part is is easy- good XML and good XSL
> standards produces good html!
>
> However, I have a tiny problem. Images. (And Metatags.) Elements
> with just attributes (and thus self-closing.)
>
> So a chunk of xsl like:
> <img alt="">
> <xsl:choose>
> <xsl:when test="$hascustom = 'true'">
> <xsl:attribute name="src"><xsl:value-of select="stream_file"
> /></xsl:attribute>
> </xsl:when>
> <xsl:otherwise>
> <xsl:attribute name="src">default.gif</xsl:attribute>
> </xsl:otherwise>
> </xsl:choose>
> </img>
>
> will produce:
> <img alt="" src="default.gif"></img>(or somethign much like it.)
>
> ...validators dislike this. They want a
> <img alt="" src="default.gif"/>
> Is there a way to make it produce a self-closing tag?


The two syntaxes are equivalent in XML.
If your software is objecting, it is broken and must be replaced with
something that works.

Are you sure you're using XHTML and not (SGML) HTML?

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Dimitre Novatchev

2006-08-24, 10:35 pm

If
<xsl:output method="html"/>
is specified, then the serializer of the XSLT processor should produce valid
html.

In case the above is ommitted, then method="xml" is used by default, and the
result tree cannot be recognised as representing HTML, then (as the "xml"
value implies) the output is a well-formed external general parsed entity --
and this seems to be your case.

Cheers,
Dimitre Novatchev


<regenesis0@XXXXXXXXXX> wrote in message
news:1156455952.099271.209730@h48g2000cwc.googlegroups.com...
> Hey-o. I'm trying to generate HTML transitional code that validates
> using XSL. For the most part is is easy- good XML and good XSL
> standards produces good html!
>
> However, I have a tiny problem. Images. (And Metatags.) Elements
> with just attributes (and thus self-closing.)
>
> So a chunk of xsl like:
> <img alt="">
> <xsl:choose>
> <xsl:when test="$hascustom = 'true'">
> <xsl:attribute name="src"><xsl:value-of select="stream_file"
> /></xsl:attribute>
> </xsl:when>
> <xsl:otherwise>
> <xsl:attribute name="src">default.gif</xsl:attribute>
> </xsl:otherwise>
> </xsl:choose>
> </img>
>
> will produce:
> <img alt="" src="default.gif"></img>(or somethign much like it.)
>
> ...validators dislike this. They want a
> <img alt="" src="default.gif"/>
> Is there a way to make it produce a self-closing tag?
>
> -Derik
>



Gadrin@gmail.com

2006-08-25, 6:43 pm


The only way I know to get /> tags would be a "two-step" approach
using a programming language. I use MSXML.

first you transform the XML into HTML via XSL using (in MSXML) via
..transformNode method.

then you take the output and run it through the two:

rdr = ObjectOpen("Msxml2.SAXXMLReader.4.0")
wrt = ObjectOpen("Msxml2.MXXMLWriter.4.0")

to produce "pretty xml".

Of course this requires a script/program. You might be able to do this
in an XSL file via the
<msxsl:script> Element.

I don't know how, but one of the MVPs here might be able to figure out
something.

Martin Honnen

2006-08-25, 6:43 pm



regenesis0@XXXXXXXXXX wrote:

> Hey-o. I'm trying to generate HTML transitional code that validates
> using XSL. For the most part is is easy- good XML and good XSL
> standards produces good html!



> will produce:
> <img alt="" src="default.gif"></img>(or somethign much like it.)
>
> ...validators dislike this. They want a
> <img alt="" src="default.gif"/>


No, if you really want HTML transitional (and not XHTML transitional)
then you need
<img alt="" src="default.gif">
as img is an empty HTML element. And as already suggested,
<xsl:output method="html"/>
in the XSLT stylesheet will take care of outputting the well defined
empty HTML elements (like e.g. img or br) the proper HTML way (e.g.
<img>, <br> ) when the XSLT processor serializes the result tree of the
transformation.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews