You need to sign in to do that
Don't have an account?
Sagar Dumbre
XSLTProcessor fails in lightening web component when added to page layout
Hi,
I am trying to apply an XSLT transformation to an XML file and display the output in div element. Below code works in the local development server. However, if I add this component in any page layout in salesforce, it failed with below error.
TypeError: XSLTProcessor constructor: 'new' is required
I am trying to apply an XSLT transformation to an XML file and display the output in div element. Below code works in the local development server. However, if I add this component in any page layout in salesforce, it failed with below error.
TypeError: XSLTProcessor constructor: 'new' is required
import { LightningElement } from 'lwc'; import testXml from '@salesforce/resourceUrl/testXml'; import testXslt from '@salesforce/resourceUrl/testXslt'; export default class MyComponent extends LightningElement { renderedCallback() { const xsltProcessor = new XSLTProcessor(); xsltProcessor.importStylesheet(testXslt); const result = xsltProcessor.transformToFragment(testXml, document); this.template.querySelector('.container').appendChild(result); } }Any suggestion to make it work in salesforce page/record layout.
I am not sure, what do you mean by child component approach? How would i transform xml to html?
Johannes Wilm has published his own adapted XLST processor on github that works well with Salesforce LWC.
XSLT-processor builds on Google's AJAXSLT which was written before XSLTProcessor() became available in browsers, but the code base has been updated to comply with ES2015+ and to make it work outside of browsers.
https://github.com/fiduswriter/xslt-processor
Do you think we should zip all the .js files from GitHub repo and add as a static resource in Salesforce? Then by using loadScript component (https://developer.salesforce.com/docs/component-library/bundle/lightning-platform-resource-loader/documentation), load all the javascript files.
The reason I am suggesting this approach because dom.js is having dependency with util.js file.