Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To "dynamically" output the value of an element and with the "number" of the child as prefix you can use <code>xsl:value-of select="position()"/&gt;</code></p> <p>Assuming your output should be text (not xml) try this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt; &lt;xsl:output method="text" indent="yes" /&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="*" mode ="printChildNr" &gt; &lt;!-- children of B or C--&gt; &lt;xsl:text&gt;children of &lt;/xsl:text&gt; &lt;xsl:value-of select="name()"/&gt; &lt;xsl:text&gt;:&amp;#10; &lt;/xsl:text&gt; &lt;xsl:for-each select="*" &gt; &lt;xsl:text&gt;#&lt;/xsl:text&gt; &lt;xsl:value-of select="position()"/&gt; &lt;xsl:text&gt; &lt;/xsl:text&gt; &lt;!-- text content of child--&gt; &lt;xsl:value-of select="text()"/&gt; &lt;xsl:text&gt;&amp;#10;&lt;/xsl:text&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/*" &gt; &lt;xsl:apply-templates select="B | C" mode="printChildNr"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>The <code>mode="printChildNr"</code> is not necessary but may help if you have to extend the xlt.</p> <p>input:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;A&gt; &lt;B&gt; &lt;b1&gt;a&lt;/b1&gt; &lt;b2&gt;b&lt;/b2&gt; &lt;/B&gt; &lt;C&gt; &lt;c1&gt;a&lt;/c1&gt; &lt;c2&gt;b&lt;/c2&gt; &lt;c3&gt;b&lt;/c3&gt; &lt;/C&gt; &lt;/A&gt; </code></pre> <p>Output:</p> <pre><code> children of B: #1 a #2 b children of C: #1 a #2 b #3 b </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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