PDA

View Full Version : javascript + xslt = a headache


virtualshock
09-09-2002, 02:29 AM
Hello. I've run into a perverbial wall trying to create a page that can dynamically display or hide html. Basically, I'm using xsl stylesheets to change an xml file into an xhtml file, and some tables, etc... have to be hidden or displayed on the page based on the parameters in the url when the page loads (www.url.com?&parameter=value&parameter=value...etc...). Since there's no way to do this using xsl alone (except for IE's script tag, which won't work on other browsers), I'm trying to wrap the transformed xhtml within a <script> tag and then use javascript to somehow do the hiding or displaying. So far, using
document.write('<xsl:apply-templates/>'); doesn't work because the statement is replaced by a bunch of <td>, etc... tags during transform and the string ends up being invalid. Also, I can't use javascript to write a <![CDATA[ ]]> or a comment wrapper around the stuff because if I do (and it works), the ');--the closing quote and paranthesis of the write statement-- end up getting displayed while everything else is hidden like it's supposed to be. Regardless of the fact that i'm probably not supposed to do this, how can I wrap the transformed xhtml in comments or have it not get displayed at all? Thanks

<xsl:for-each select="./column">
<script type="text/javascript">
if (!g_isContentVisible("<xsl:value-of select="@id"/>"))<![CDATA[ {
document.write("<");
document.write("!--");
}
]]></script>

<xsl:apply-templates select="."/>

<script type="text/javascript">
if (!g_isContentVisible("<xsl:value-of select="@id"/>"))<![CDATA[ {
document.write("-->");
}
]]></script>
...more stuff here...
</xsl:for-each>