Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating incremental ID for xml attributes using XSLT
    text
    copied!<p>I have following XSL.</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="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:element name="root"&gt; &lt;xsl:apply-templates select="ModelDefinition/ContainerSpecNode"/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="ContainerSpecNode"&gt; &lt;xsl:element name="item"&gt; &lt;xsl:attribute name="id"&gt;&lt;xsl:value-of select="@specId"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="pathId"&gt;&lt;xsl:value-of select="@pathId"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="specId"&gt;&lt;xsl:value-of select="@specId"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="rel"&gt;&lt;xsl:value-of select="@specType"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:element name="content"&gt; &lt;xsl:element name="name"&gt; &lt;xsl:value-of select="shortName"/&gt; &lt;xsl:if test="(@minimumCardinalityCount = '0') or (@maximumCardinalityCount != '1')"&gt; [&lt;xsl:value-of select="@minimumCardinalityCount"/&gt;..&lt;xsl:value-of select="@maximumCardinalityCount"/&gt;]&lt;/xsl:if&gt; &lt;/xsl:element&gt; &lt;/xsl:element&gt; &lt;xsl:apply-templates select="propertySpecs/PropertySpecNode"&gt; &lt;xsl:sort select="shortName"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Here I want to create create incremental unique number for ID attributes of Item element for each containerSpecNode just like "Tree_node_1" , "Tree_Node_2" and so on... Here I modified code like this.</p> <pre><code>. . . . . . &lt;xsl:element name="item"&gt; &lt;xsl:variable name="count"&gt; &lt;xsl:number/&gt; &lt;/xsl:variable&gt; &lt;xsl:attribute name="id"&gt;&lt;xsl:value-of select="'Tree_Node_'"/&gt;&lt;xsl:value-of select="$count+1"/&gt;&lt;/xsl:attribute&gt; </code></pre> <p>It increments count value but not for all ContainerSpecNode. Some ID have duplicate value.</p> <p>I want create for each ContainerSpecNode. How can i do this. Can I use for-each loop? and How?</p>
 

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