How to use an incremented counter to provide a unique id in XSLT?

后端 未结 4 1992
故里飘歌
故里飘歌 2021-01-20 01:40

I am using XSLT to convert a very large XML document into (X)HTML. For some of the tags I am converting them to a

. I would like to be able to create
4条回答
  •  无人共我
    2021-01-20 02:21

    The natural/idiomatic/failsafe solution would be:

    It's not incrementing, but it's guaranteed to be unique. And it's going to produce HTML-valid ID strings (name tokens).

    EDIT: If it must be incrementing, do something like the following:

    
    
    
    
    
      

    You can use format-number() to adapt the output of position() to your needs.

    position() will return the node position relative to the "batch" that is currently being processed. With an explicit call to you make sure that they are numbered the way you want.

提交回复
热议问题