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 7048245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:52:06+00:00 2026-05-28T02:52:06+00:00

Let’s say I have some XSL transforming XML. Is it possible for the same

  • 0

Let’s say I have some XSL transforming XML. Is it possible for the same XSL sheet to run a second sweep over the resultant XML? For example, let’s say my XSL turns

<xml>
    <animal><dog>Rex</dog></animal>
    <animal><dog>Henry</dog></animal>
    <animal><dog>Fido</dog></animal>
</xml>

into

<xml>
    <dog>Rex</dog>
    <dog>Henry</dog>
    <dog>Fido</dog>
</xml>

I don’t want to output that; rather, I then want to perform more XSL based on THAT, i.e. resultant, XML structure.

A practical example? I want to append to each dog node the number of proceeding dog siblings it has. So it would end up like:

<xml>
    <dog>Rex (2)</dog>
    <dog>Henry (1)</dog>
    <dog>Fido (0)</dog>
</xml>

This could not be done on the first sweep because in the beginning XML, the dog nodes were not siblings – they each lived inside an animal node.

[EDIT: I know this could be done by interrogating instead the index of the parent animal node, but that’s only for this contrived example; generally, I still need to know how to act on transformed XML – if it’s even possible]

I hope that makes some sort of sense. If there is a really easy way to do this, go easy on me, as I’m no XSL ninja…

Thanks in advance

  • 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-28T02:52:07+00:00Added an answer on May 28, 2026 at 2:52 am

    You can use modes on templates to process nodes more than one time but with different transformations. So you could do e.g.

    <xsl:variable name="result1">
      <xsl:apply-templates select="xml" mode="m1"/>
    </xsl:variable>
    
    <xsl:variable name="result2">
      <xsl:apply-templates select="$result1/xml" mode="m2"/>
    </xsl:variable>
    
    <xsl:template match="/">
      <xsl:copy-of select="$result2"/>
    </xsl:template>
    
    <!-- now put templates for the modes here -->
    

    That above is fine only with XSLT 2.0 however, with XSLT 1.0 you have the drawback that a temporary result is a result tree fragment which you need to convert into a node-set first with an extension function like exsl:node-set so with XSLT 1.0 you need e.g.

    <xsl:variable name="result1">
      <xsl:apply-templates select="xml" mode="m1"/>
    </xsl:variable>
    
    <xsl:variable name="result2">
      <xsl:apply-templates select="exsl:node-set($result1)/xml" mode="m2"/>
    </xsl:variable>
    
    <xsl:template match="/">
      <xsl:copy-of select="$result2"/>
    </xsl:template>
    
    <!-- now put templates for the modes here -->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the string: hello world; some random text; foo; How could
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's say i have this block of code, <div id=id1> This is some text
Let's say I have these two tables: ParentDataItem ParentDataItemID ...some other fields... ChildDataItem ChildDataItemID
Let's say I have two same strings inside an ArrayList... is there a way
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have a drive such as C:\ , and I want to
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,

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.