I want to convert one xml to another xml by using XSLT2.0.While doing so, i want to find out some XML elements indexes with respect to my scenaio i explained here...
This is 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:sdt>
<w:sdtContent>
<w:p>
<w:pPr>
<w:pStyle w:val="TOC"></w:pStyle>
</w:pPr>
</w:p>
</w:sdtContent>
</w:sdt>
<w:p> <!-- index value 0 -->
</w:p>
<w:p> <!-- index value 1 -->
</w:p>
<w:Bookmark></w:Bookmark> <!-- index value 2 -->
<w:Bookmark></w:Bookmark> <!-- index value 3 -->
<w:pict></w:pict> <!-- index value 4 -->
<w:p> <!-- index value 5 -->
</w:p>
<w:Bookmark></w:Bookmark> <!-- index value 6 -->
<w:Bookmark></w:Bookmark> <!-- index value 7 -->
<w:p> <!-- index value 8 -->
</w:p>
</w:body>
</w:document>
So, I want to find the <w:Bookmark>
elements indexes.
- If my xml documents contains this elements then i want to create one element named 'Bookmark' and set the attribute 'index'.
- If my xml documents does not contains this elements don't do anything...
The Index Count starts from zero and i need to omit <w:sdt>
elements from calculating index.Please See my comment on the xml document.
My Required output is :
<Document>
<Bookmark indexes="2,3,6,7">
</Bookmark>
</Document>
Try this ...
... or this equivalent without functions ...
This short and simple transformation uses
<xsl:number>
:when applied on the provided XML document:
the wanted, correct result is produced: