Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In 90% of XSLT questions, the greatest challenge, is not the technical aspect of the question, but rather how to articulate the rules of transformation in the form of match pattern and corresponding output. Rather than give you a style-sheet, I'll give you a pattern &amp; output view of your question. You should be able to make a style-sheet from this. There are no special techniques involved.</p> <p>Comparing your input and output documents, I would describe the rules of transformation as follows.</p> <ol> <li>Copy the input document to the output with the following exceptions.</li> <li><p>Precede the &lt;body> with the following literals</p> <pre><code>&lt;script type="t/j" src="pqr.js" /&gt; &lt;script type="t/j" src="pqr.js" /&gt; </code></pre></li> <li><p>Append to the &lt;body> element attributes @onload="load()" and @onunload="unload()".</p></li> <li>For any &lt;div> elements that have @id=123, change @class to QT and id to 456.</li> <li>For any &lt;script> elements change @src="xyz.js" to "lmn.js".</li> <li>For any &lt;script> elements <strong>in the body</strong> with @src="abc.js", delete.</li> <li><p>Wrap any &lt;div> elements that have @class="iD" in a &lt;form> and just before the close of the form, include the following literals</p> <pre><code>&lt;br/&gt;&lt;input type="submit" name="sub" value="Done"/&gt; </code></pre></li> <li><p>Replace any &lt;div> elements with @id="ta12" with this replacement:</p> <pre><code>&lt;div id="pa" value="10" /&gt; </code></pre></li> <li><p>Copy any &lt;div class="iDev">, except replace its children with the following literals</p> <pre><code>&lt;div id="ta8" class="bl" style="dis:bl"&gt;XYZ&lt;/div&gt; &lt;br/&gt; &lt;input type="radio" name="ke8" value="0" /&gt; &lt;div id="tab8" class="bl" style="dis:bl"&gt;T&lt;/div&gt; &lt;input type="radio" name="ke8" value="1" /&gt; &lt;div id="tab8" class="bl" style="dis:bl"&gt;F&lt;/div&gt; </code></pre></li> </ol> <h2>Update</h2> <p>The OP has asked for a template for point 5. So here it is. This is a general solution on how to copy a node, just changing one attribute ...</p> <pre><code>&lt;xsl:template match="xhtml:script[@src='xyz.js']"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*[not(@src)]" /&gt; &lt;xsl:attribute name="src"&gt;lmn.js&lt;/xsl:attribute&gt; &lt;xsl:apply-templates select="node()" /&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; </code></pre> <p>If you didn't mind having a less general solution and could afford to assume that the script element would have no children and only one other attribute @type="t/j" , you could for example, use a more concise and specific template like so (but I would not recommend it - I am just laying out your options ...</p> <pre><code>&lt;xsl:template match="xhtml:script[@src='xyz.js']"&gt; &lt;xhtml:script type="t/j" src="lmn.js" /&gt; &lt;/xsl:template&gt; </code></pre> <p>And for point 6 it is ...</p> <pre><code>&lt;xsl:template match="xhtml:body//xhtml:script[@src='abc.js']" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload