Jump to content

Editing Of Xsl Using Javascript


Almeida
 Share

Recommended Posts

Hi,I have a local XML-File with content that looks like that

<Data>	<Timestamp>30.10.2009 13:14:25</Timestamp>	<LogLevel>Developer</LogLevel>	<Component>TestComponent</Component>	<Log />	<Message>Test</Message>	<Source>TestFunction()</Source>  </Data>

and i have a XSL-File which creates an table as HTML code to display the data properly.I also have a Javascript which reads the Components from the XML and generates an dropdown-menu with all of the components as entries.Now, I want to edit the XSL file on the fly, depending on which component I selected from my dropdown und reuse that XSL on my XML, so that only the selected Components are displayed.Any idea, how I can do this?I thought of taking a string with the XSL text in it and edit this as I wish. But how can I then use this string as my XSL?Or is there an easier way of achieving my goal?Any help is appreciated!Thanks, Almeida

Link to comment
Share on other sites

I don't think you need to edit the XSLT stylesheet, instead you can simply define a global parameter in the stylesheet and set that with the API of your XSLT processor before you run the transformation:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:param name="p1" select="''"/><xsl:template match="/">  <xsl:apply-templates select="root/foo[$p1 = '' or $p1 = bar]"/></xsl:template>...</xsl:stylesheet>

See https://developer.mozilla.org/en/Using_the_...Transformations on how to set parameters before running a transformation with Mozilla (and Opera and Safari as they expose the same API).

Link to comment
Share on other sites

IE uses MSXML for XML parsing and XSLT transformation. The MSXML API is documented here: http://msdn.microsoft.com/en-us/library/ms763742(VS.85).aspxYou will need to use the method AddParameter: http://msdn.microsoft.com/en-/library/ms762312(VS.85).aspxAs for adapting the code to your needs, please show us the XSLT you have currently that outputs the complete data. And I suspect your XML is also not complete, at least from that single 'Data' element I am not sure what you want to filter. Do you get the 'Component' element contents from that drop drown list?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...