Showing posts with label browser. Show all posts
Showing posts with label browser. Show all posts

2021-07-11

XSLT 1.0 in-browser Q&A

  • How to get XSLT path from within XSLT?

<xsl:value-of select="substring-before(substring-after(/processing-instruction('xml-stylesheet'),'href=&quot;'),'&quot;')"/>

XML: <?xml-stylesheet type="text/xsl" href="../AsTable.xsl" ?>

Gives: ../AsTable.xsl

  • How to get relative URL of  specific XSLT from XML?

<xsl:value-of select="substring-before(substring-after(/processing-instruction('xml-stylesheet'),'href=&quot;'),'AsTable.xsl&quot;')"/>

    Gives: ../


    • How to get Javascript URL relative to XSLT applied to XML as processing instruction?
    XSLT:
    <xsl:param name="baseUrl" select="substring-before(substring-after(/processing-instruction('xml-stylesheet'),'href=&quot;'),'AsTable.xsl&quot;')"  />
    <script type="module" src="{$baseUrl}XmlView.js">/**/</script> 

    Gives: ../XmlView.js


      • list of unique children tags (each last)
      *[ not( name() = name(following-sibling::*) ) ]
      • how to output XSL from XSL
      Add namespace with altered URL, namespace-alias, use the namespace in output:
      <xsl:stylesheet version="1.0"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xvxsl="http://www.w3.org/1999/XSL/TransformAlias">
      <!--
      * get entries for table presentation and
      * fills in xsl:template mode="DisplayAs" for each
      -->
      <xsl:output method="xml" />
      <xsl:namespace-alias stylesheet-prefix="xvxsl" result-prefix="xsl"/> ...
      <xvxsl:template mode="DisplayAs" match="{$xPath}">
      • how to debug XSL? 
      Currently the most convenient way is given by Visual Studio Pro edition. Trial available.

      2019-05-13

      @xmlaspect/reactive-xml - reasons of creation

      For ApiFusion the import documentation from sources into MediaWiki pages become a sequence for processing various data from different sources, mostly data and html web services. This mix when implemented with classic asynchronous patterns like callbacks, Promise call chain, or `async` JS keyword become a spaghetti code mess hard to code and maintain.

      An another use case inspired reacive-xml creation is a web crawling for data mining. In my case finding who will share the floor on various dance competitions.

      More on apifusion.com/@xmlaspect/reactive-xml 
      Open source work in progress, meanwhile xml4jQuery gives similar solution.

      2017-05-18

      JS in browser tricks

      Convert arguments, NodeList, attributes to normal JS array

      Little notes for myself
      Array.prototype.slice.call(arguments).forEach( el=>console.log(el) ) // arguments to normal JS array
      Object.keys({a:0}) // keys to array
      
      
      [... this.attributes].filter( el=>!el.name.indexOf('data-') ).forEach( el=> console.log(el.name, el.value) ) // DomElement attributes (NamedNodeMap) to array es6
      Array.from(this.attributes).filter( el=>!el.name.indexOf('data-') ) // -||- es5 + shim
      Array.prototype.forEach.call(document.querySelectorAll( 'input[type=checkbox]' ), item => item.checked = true ); // es5
      
      // ES6 
      
      let divsArray = [...document.querySelectorAll('div')]; // Convert NodeList to Array
      
      let argsArray = [...arguments]; // Convert Arguments to Array
      
      For IE and legacy use polyfills from core-js or babel-polyfill

      2013-10-20

      RE: How to solve the lack of a real multi-threading in JavaScript?

      Recently on LinkedIn post the question was raised. And I was surprised how "respectable" people on JS community are struggling in their insulated "JS" world. While there are many ways to solve the given problem none was even exposed. It seems to be a good opportunity for people with out of the box thinking and bigger knowledge. But to gain the advantage there is a need for willingness to listen from community. Is there any?

      On subj:
      While JS is single threaded by definition, there are lot of ways to have parallel processing from graphics computation to data conversion. XSLT, SVG & CSS transforms just to name a few. Depend of your needs big chance there is a solution.
      @Jeff Schwartz. The JS loading and parsing is multithreaded in Chrome. Running is not. XSLT uses internally multithreaded processing; frames have own threads. And so on. I had 2 alerts on the screen quite a bit when tuned communication in between. Have whole HTML rendered as a string with multithreaded XSLT and than passed to single-threaded DOM rendering. Please do not confuse people if do not know what you are talking about. 
      There is no multithreaded JS(Web Workers aside). But there are numerous ways to use multithreading in browser from JS and between JS VMs.