How to append a number to an ID inside an XSL file

后端 未结 1 1213
独厮守ぢ
独厮守ぢ 2021-01-24 06:19

I have the following XSL file which will be repeated many times (in my case 4 times):


    
相关标签:
1条回答
  • 2021-01-24 06:47

    In case the provided XSLT part is e.g. in an <xsl:for-each> loop, you can use position() to get an incremented value (the current position in the loop) and concat():

    <span id="concat('spnCity', position())">
    

    Update as suggested approach didn't work in the settings:

    Two different kind of notations that should work are:

    <span>
      <xsl:attribute name="id" select="concat('spnCity', position())"/>
    </span>
    

    and

    <span>
      <xsl:attribute name="id">
        <xsl:value-of select="concat('spnCity', position())"/> 
      </xsl:attribute>
    </span>
    

    The content can just be added after the attribute:

    <span>
      <xsl:attribute name="id">
        <xsl:value-of select="concat('spnCity', position())"/> 
      </xsl:attribute>
      <xsl:value-of select="Html/root/lcGroup/txtCity" />
    </span>
    

    Just created a Demo with both versions.

    0 讨论(0)
提交回复
热议问题