Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8196405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:27:55+00:00 2026-06-07T05:27:55+00:00

I want to convert one xml to another xml by using XSLT2.0.While doing so,

  • 0

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.

  1. If my xml documents contains this elements then i want to create one element named ‘Bookmark’ and set the attribute ‘index’.
  2. 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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:27:57+00:00Added an answer on June 7, 2026 at 5:27 am

    Try this …

    <xsl:stylesheet 
      version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:fn="http://www.w3.org/2005/xpath-functions"
      xmlns:user="http://http://stackoverflow.com/questions/11356668"
      exclude-result-prefixes="xs fn w user">
    
    <xsl:output indent="yes"/>
    
    <xsl:function name="user:bookmark-index" as="xs:string">
      <xsl:param name="bookmark-node" as="element()"/>
      <xsl:for-each select="$bookmark-node">
        <xsl:value-of select="count( preceding-sibling::*) -
                              count( preceding-sibling::w:sdt)" />
      </xsl:for-each>
    </xsl:function>
    
    <xsl:template match="/">
     <Document>
      <Bookmark indexes="{
        fn:string-join( for $i in w:document/w:body/w:Bookmark return user:bookmark-index( $i), ',')
        }" />
     </Document>
    </xsl:template>
    
    </xsl:stylesheet>
    

    … or this equivalent without functions …

    <xsl:stylesheet 
      version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:fn="http://www.w3.org/2005/xpath-functions"
      exclude-result-prefixes="xs fn w">
    
    <xsl:output indent="yes"/>
    
    <xsl:template match="/">
     <Document>
      <Bookmark indexes="{
        fn:string-join( for $i in w:document/w:body/w:Bookmark return
                xs:string( count($i/preceding-sibling::*) -
                           count($i/preceding-sibling::w:sdt)),
                      ',')
        }" />
     </Document>
    </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert one xml format to another specified format by using xslt.
I want to convert one xml file into another xml file using xslt.here, i
In an XSLT, I want to convert an XML document to another one. The
I have an HTML file and i want to convert to XML only using
I want to be able to convert from one currency to another, I found
I'm trying convert xml from one format to other using the XslCompiledTransform in c#.
I'm using FOP to convert XML into a PDF. One of the fields that
I have three lists that I want to convert into one list. When I
I have a directory full of JPEGs. I want to convert every one of
I want to convert this linear loop into a concurrent one: for(Item item :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.