scopley Posted January 12, 2007 Share Posted January 12, 2007 I am trying to create a global variable to number specific elements during transformation. I need to be able to count different elements throughout the original xml. The original XML would look like this:<procblk><presteps><seqlist numstyle="alphalc"><item><paratext>TEXT</paratext></item></seqlist></presteps><procsteps><seqlist numstyle="alphalc"><title>TITLE 1</title><item><paratext>TEXT</paratext></item><seqlist numstyle="alphalc"><title>TITLE 2</title><item><paratext>TEXT</paratext></item></prosteps></problk>I am trying to create a variable that will count the presteps element and the title element within the procsteps element. Based on the XML above the desired result is:<presteps> = 01TITLE1 = 02TITLE2 = 03The best I can get is 01 for each. Any help would be greatly appreciated. Link to comment Share on other sites More sharing options...
boen_robot Posted January 13, 2007 Share Posted January 13, 2007 Perhaps<xsl:param name="counter" select="count(/*/presteps) + count(//title)"/>Will give the end count needed.I mean, whatever you're REALLY trying to achieve, it probably has something do to with the sum of all those.And what is your FINAL goal btw? Link to comment Share on other sites More sharing options...
scopley Posted January 18, 2007 Author Share Posted January 18, 2007 Perhaps<xsl:param name="counter" select="count(/*/presteps) + count(//title)"/>Will give the end count needed.I mean, whatever you're REALLY trying to achieve, it probably has something do to with the sum of all those.And what is your FINAL goal btw?My final goal is to id tasks and steps. Should look like this:XML Input file:<procblk>!--THIS IS PRELIMINARY STEPS - TASK 01--!<presteps><seqlist numstyle="alphalc"><item><paratext>TEXT</paratext></item></seqlist></presteps>!--THIS SHOULD BE TASK 02--!<procsteps><seqlist numstyle="alphalc"><title>TITLE 1</title><item><paratext>TEXT</paratext></item>!--THIS SHOULD BE TASK 03--!<seqlist numstyle="alphalc"><title>TITLE 2</title><item><paratext>TEXT</paratext></item></prosteps></problk>XML Desired Output:<task id="tk01"><title>PRELIMINARY STEPS</title><step1 id="st0101><para>TEXT</para></step1></task><task id="tk02"><title>TITLE 1</title><step1 id="st0201><para>TEXT</para></step1></task><task id="tk03"><title>TITLE 2</title><step1 id="st0301><para>TEXT</para></step1></task>Thanks for your help! Link to comment Share on other sites More sharing options...
boen_robot Posted January 27, 2007 Share Posted January 27, 2007 I think I get it.The first thing you'll need is the position() function. It shows the position of the current node in the current context. In other words: <xsl:for-each select="/procblk/*"><xsl:value-of select="position()"><br /></xsl:for-each> will produce 12 If you do something else on each position, this power increases... In your particular case though, a simple: //seqlist might do the trick better. That is: <xsl:for-each select="//seqlist"><xsl:value-of select="position()"><br /></xsl:for-each> will produce exactly 123 which is the start you need to get the rest of the output the way you want it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now