spectacularbob
spectacularbob

Reputation: 3218

XSL: Generate a global integer id that increments itself

I have an XML format that I need to generate via XSL that has an odd quirk. Every element in the target schema that has an id attribute, must be in sequence with all other id attributes, regardless of the element name. Here is a very simplified example of what I mean:

Input.XML

<list>
  <booklist>
    <book>
  </booklist>
  <cdlist>
    <cd />
    <cd />
  </cdlist>
  <periodicallist>
    <periodical>
  </periodicallist>
</list>

Output.XML

<mediaLibrary>
  <book id="1" />
  <cdList>
    <cd id="2" />
    <cd id="3" />
  </cdList>
  <periodical id="4" />
</mediaLibrary>

I know that XSL variables are immutable and I haven't had any luck with xsl:number, though I am very new to XSL. Is there a way in XSL to do this?

Upvotes: 1

Views: 83

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116959

I haven't had any luck with xsl:number

How about:

<xsl:number level="any" count="book | cd | periodical"/>

Upvotes: 2

Related Questions