This is my XML Document.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p> <!-- index 0 -->
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>
Paragraph1
</w:t>
</w:r>
</w:p>
<w:p> <!-- index 1 -->
<w:pPr>
<w:pStyle w:val="TOC1"/>
</w:pPr>
<w:r>
<w:t>
TOC1
</w:t>
</w:r>
</w:p>
<w:p> <!-- index 2 -->
<w:pPr>
<w:pStyle w:val="TOC2"/>
</w:pPr>
<w:r>
<w:t>
TOC2
</w:t>
</w:r>
</w:p>
<w:p> <!-- index 3 -->
<w:pPr>
<w:pStyle w:val="TOC3"/>
</w:pPr>
<w:r>
<w:t>
TOC3
</w:t>
</w:r>
</w:p>
<w:p> <!-- index 4 -->
<w:pPr>
</w:pPr>
<w:r>
<w:t>
Paragraph2
</w:t>
</w:r>
</w:p>
<w:p> <!-- index 5 -->
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>
Paragraph3
</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
So, Now i want to calculate following two things
1.Count starting index position of element that having <w:pStyle> value starting with “TOC”.Here it starting in first<w:p> element(Assume index starting from ‘0’).so, i want following output
2.Total number of that having <w:pStyle> value starting with “TOC”.I have count this by following expression.So, Please Guide me to get first one…
<xsl:attribute name="totalTOC">
<xsl:value-of select="count(//w:body/w:p[w:pPr[w:pStyle[starts-with(@w:val,'TOC')]]])"/>
<xsl:attribute>
My Required output is:
<Document>
<TOC startIndex="1" totalTOC="3"/>
</Document>
You can use the
preceding-siblingaxis as such:count(//w:body/w:p[w:pPr[w:pStyle[starts-with(@w:val,'TOC')]]][1]/preceding-sibling::*).This will select the first element that meets your criteria and return the count of its preceding siblings (the current index). For a one-based index, simply add 1.