Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>This transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="http://www.w3.org/2005/07/scxml" &gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="node()|@*" name="identity"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="s:state"&gt; &lt;xsl:variable name="vNum"&gt; &lt;xsl:number level="any" count="s:state"/&gt; &lt;/xsl:variable&gt; &lt;xsl:copy&gt; &lt;xsl:copy-of select="@*"/&gt; &lt;xsl:attribute name="stateId"&gt; &lt;xsl:value-of select="@id"/&gt; &lt;/xsl:attribute&gt; &lt;xsl:attribute name="id"&gt; &lt;xsl:value-of select="$vNum -1"/&gt; &lt;/xsl:attribute&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided XML document</strong>:</p> <pre><code>&lt;scxml xmlns="http://www.w3.org/2005/07/scxml"&gt; &lt;state id="Compound1"&gt; &lt;state id="Basic1"/&gt; &lt;state id="Basic2"/&gt; &lt;state id="Basic3"/&gt; &lt;/state&gt; &lt;/scxml&gt; </code></pre> <p><strong>produces the wanted, correct output</strong>:</p> <pre><code>&lt;scxml xmlns="http://www.w3.org/2005/07/scxml"&gt; &lt;state stateId="Compound1" id="0"&gt; &lt;state stateId="Basic1" id="1"/&gt; &lt;state stateId="Basic2" id="2"/&gt; &lt;state stateId="Basic3" id="3"/&gt; &lt;/state&gt; &lt;/scxml&gt; </code></pre>
 

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