Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to prevent <script></script> from collapsing to <script />

Status
Not open for further replies.

gacaccia

Technical User
May 15, 2002
258
US
i'm using an xslt file to output an html file from an xml file. the output html file needs to include a link to a javascript file. to that end, the xslt file includes...

Code:
<xsl:output method="html" encoding="utf-16"/>
<xsl:template match="/">
  <html>
    <head>
      <script type="text/javascript" src="QTPFrameworkDocCode.js"></script>
    </head>

my problem is that the actual output concerning the script link in the html file gets collapsed to...

Code:
<script type="text/javascript" src="QTPFrameworkDocCode.js" />

which apparently is invalid because the entire html page will fail to display. i have to manually edit the html and change it back to <script></script> instead of <script />. how do i get the xslt file to faithfully output what i want?

thanks,

glenn
 
If I remember OK, XML or XHTML requires to close the tags.

Is that your complete XSLT file?

Cheers,
Dian
 
Put something that is not whitespace between the opening and closing tags. <xsl:comment> might be helpful.

You might also want to consider using doctype to force the browser into a more helpful mode.


Tom Morrison
 
dian,

yeah, i found a similar suggestion on another post. i ended up going with...

Code:
<script type="text/javascript" src="QTPFrameworkDocCode.js">
<xsl:text>
</xsl:text>
</script>

which preserves the closing tag.

thanks,

glenn
 
If you specify output method being html, as it seems you're using, most implementations will automatically output the script tag in the form <script ...></script>. They won't output it in the shortened empty tag form. If it is the case where output method is "xml", then the behaviour would be very different. And if you send/stream the output to an user agent or file system expecting html page instead, it would then pose a technical problem if it is in the shortened empty tag format.

Which implementation are you using to see that behaviour?
 

if by implementation you're referring to the output method, then "html" as show in the original post. the tranformation is being run through a C# application, so perhaps there's an issue there. the basic code looks like...

Code:
XslCompiledTransform transformer = new XslCompiledTransform();
transformer.Load(xslFile);
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(xmlContent);
transformer.Transform(xdoc.CreateNavigator(), XmlWriter.Create(htmlFile));

perhaps i need to be specifying an output type in there for the xmlwriter. it may be that its settings are overriding those specified in the xslt file.
 
By implementation, I meant different xslt processor implementation, like msxml2, xalan, saxon,...

I think your streaming to XmlWriter may be a reason.

To put the worry behind, you may do what you've done. Some alternative you may consider is to insert a non-breakable space (&#xa0;) or a zero-width space (&#x200b;), then it make the intension in the xsl document more explicit to the point not relying on knowledge behind: the default treatment of white-space of the processor.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top