xml - XPath - determine the element position -


I want to create an index for each table (determine the position in XML) but the problem is that tables are different Depth I am planning to process XML with XSLT conversion for FO. How do I have any ideas?

Sample XML

  & lt; Document & gt; & Lt; Table & gt; ... & lt; / Table & gt; & Lt; Section & gt; & Lt; Table & gt; ... & lt; / Table & gt; & Lt; Sub-section & gt; & Lt; Table & gt; ... & lt; / Table & gt; & Lt; / Sub-section & gt; & Lt; / Section & gt; & Lt; / Documents & gt;    

@Tormark's solution is not completely correct And when there are nested tables, present the wrong result in the case.

The reason for this is that XPath predecessor and ancestor axis are non-overlapping

Returns the desired number one The correct XPath expression is:

  count (ancestor :: table | preceding :: table) + 1   

Then, use :

  & lt; Xsl: template match = "table" & gt; & Lt; Table id = "tbl_ {count (ancestor :: table | preceding :: table) + 1}" & gt; & Lt ;! - Further processing - & gt; & Lt; / Table & gt; & Lt; / XSL: Templates & gt;    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -