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

  • SEARCH
  • Home
  • 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 938295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:37:12+00:00 2026-05-15T21:37:12+00:00

This is my Source-XML. It is originally a Word-ML which have been reduced to

  • 0

This is my Source-XML. It is originally a Word-ML which have been reduced to an own structure. Elements with name “aaa” can have any kind of name. The problem is the handling of footnotes:

<root>
  <doc>
    <comment>text text text <footnote id="1" > text text text</comment>
    <aaa>text text text</aaa>
    <aaa>text text text<footnote id="2" /> text text text </aaa>
    <aaa>text text text<aaa/> text <footnote id="3" symbol="*"/></aaa>
    <aaa>text text text text</aaa>
    <aaa>text text text text<aaa>text text text<footnote id="4"  /></aaa></aaa>
 <aaa>text text text text<aaa>text text text<footnote id="4"  /></aaa></aaa>
 <aaa>text text text text<aaa>text text text<footnote id="5"  /></aaa></aaa>
    <aaa>text text text</aaa>
  </doc>
</root>

I have to transform this Source-XML in another XML. One thing i have to do is to replace the footnotes with the correspondig Number.

But it is not possible to only use the ID-Attribute. The ID is only an internal number. The footnotes should be progressive an there are following conditions:

  • Condition 1: “footnotes” that are a child of node “comment” should be ignored. the whole node “comment” is ignored.
  • Condition 2: “footnotes” that have a symbol-attribute do not count (i have to show the symbol and not the number)
  • Condition 3: it is possible that some notes have the same id (only a low percentage, but sometimes there are more links to the same footnote).

The Output should look like this (structure is not the same, only the handling of the footnotes is for interest now):

<root>
  <doc>
    <aaa>text text text</aaa>
    <aaa>text text text[1] text text text </aaa>
    <aaa>text text text<aaa/> text [*]</aaa>
    <aaa>text text text text</aaa>
    <aaa>text text text text<aaa>text text text[2]</aaa></aaa>
 <aaa>text text text text<aaa>text text text[2]</aaa></aaa>
 <aaa>text text text text<aaa>text text text[3]</aaa></aaa>
    <aaa>text text text</aaa>
  </doc>
</root>

My first thought was to have a global counter-variable which i increment according to the conditions. But since variables in XSLT are immutable it is not really an option.

I also tried to count the previous footnotes which occur before the current footnote.

        <xsl:template match="footnote">
         <xsl:call-template name="getFootnoteNumber">
          <xsl:with-param name="footNodeId" select="@id"/>
         </xsl:call-template>
        </xsl:template>

    <!-- simple template which only counts the footnotes
    that occur before the current footnode 
    the conditions 1, 2 and 3 are not yet included -->
        <xsl:template name="getFootnoteNumber">
           <xsl:param name="footNodeId"/>
           <xsl:value-of select="count(//footnote[position()&lt;=$footNodeId])"></xsl:value-of>     
    </xsl:template>
    <!-- i mostly get value "0", 
    or other strange numbers: for footNodeID=45 i get value 75, 
    doesn't really work-->

Is there a possibility to develop a global counter?

Or do i have to go on the other way with counting the previous footnotes? Although i don’t really know how to implement condition 3.

Greetings and thx for any answer
cpt.oneeye

  • 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-05-15T21:37:12+00:00Added an answer on May 15, 2026 at 9:37 pm

    XSLT 2.0 solution:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes"/>
    
     <xsl:key name="kPosById" match="@pos" use="../@id"/>
    
     <xsl:variable name="vdistinctFootnotes">
      <xsl:for-each-group group-by="@id" select=
        "/*/*/*[not(self::comment)]//footnote[not(@symbol)]">
    
        <xsl:copy>
          <xsl:copy-of select="@*"/>
          <xsl:attribute name="pos" select="position()"/>
        </xsl:copy>
      </xsl:for-each-group>
     </xsl:variable>
    
        <xsl:template match="node()|@*">
          <xsl:copy>
             <xsl:apply-templates select="node()|@*"/>
          </xsl:copy>
        </xsl:template>
    
        <xsl:template match="footnote">
          <xsl:value-of select=
          "concat('[', key('kPosById', @id, $vdistinctFootnotes), ']')"/>
        </xsl:template>
    
        <xsl:template match="footnote[@symbol]">
         <xsl:value-of select="concat('[', @symbol, ']')"/>
        </xsl:template>
    
        <xsl:template match="footnote[ancestor::comment]"/>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided document (corrected to be wellformed):

    <root>
      <doc>
        <comment>text text text <footnote id="1" /> text text text</comment>
        <aaa>text text text</aaa>
        <aaa>text text text<footnote id="2" /> text text text </aaa>
        <aaa>text text text<aaa/> text <footnote id="3" symbol="*"/></aaa>
        <aaa>text text text text</aaa>
        <aaa>text text text text<aaa>text text text<footnote id="4"  /></aaa></aaa>
     <aaa>text text text text<aaa>text text text<footnote id="4"  /></aaa></aaa>
     <aaa>text text text text<aaa>text text text<footnote id="5"  /></aaa></aaa>
        <aaa>text text text</aaa>
      </doc>
    </root>
    

    the wanted result is produced:

    <root>
      <doc>
        <comment>text text text  text text text</comment>
        <aaa>text text text</aaa>
        <aaa>text text text[1] text text text </aaa>
        <aaa>text text text<aaa/> text [*]</aaa>
        <aaa>text text text text</aaa>
        <aaa>text text text text<aaa>text text text[2]</aaa></aaa>
     <aaa>text text text text<aaa>text text text[2]</aaa></aaa>
     <aaa>text text text text<aaa>text text text[3]</aaa></aaa>
        <aaa>text text text</aaa>
      </doc>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.