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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:15:24+00:00 2026-05-30T12:15:24+00:00

I have a table that is calculated using many variables. During the calculation, i

  • 0

I have a table that is calculated using many variables. During the calculation, i keep record of these calculations in a xml file.

The thing is I need to format this xml in different layouts

  • one starting from the invoices
  • the other starting from the column names.

Fore each ‘invoice’ there is a ‘cost’ specified which can be a part from the invoice’s value and each ‘cost’ is being placed in a column from the table.

My XML is like this:

<table>
    <invoices>
        <invoice id="1" value="230" supplier="First supplier"/>
    </invoices>
    <costs>
        <cost id="1" invoice="1" column="2" value="100">
            <calculation>
                <tenant name="Tenant1" cost="30" />
                <tenant name="Tenant2" cost="70" />
            </calculation>
        </cost>
        <cost id="2" invoice="1" column="1" value="130">
            <calculation>
                <tenant name="Tenant1" cost="50" />
                <tenant name="Tenant2" cost="50" />
            </calculation>
            <calculation>
                <tenant name="Tenant1" cost="10" />
                <tenant name="Tenant2" cost="20" />
            </calculation>
        </cost>
    </costs>
    <columns>
        <column id="1" name="Column name 1"/> 
        <column id="2" name="Column name 2"/> 
    </columns>
</table>

So my expected output would be something like

Column name
    Costs from which invoice
        Calculations

Or

Invoice
    Spread over a column based on cost
        Calculations

My XSL looks something like this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
            <xsl:for-each select="table/costs/cost">
                <xsl:call-template name="cost"></xsl:call-template>
                <h1>Mere</h1>
            </xsl:for-each>
        </html>
    </xsl:template>
    <xsl:template match="cost" name="cost">
        <xsl:apply-templates select="invoice"></xsl:apply-templates>
        <h1>Cheltuiala <xsl:value-of select="@id"></xsl:value-of></h1>
        <ul>
            <li>
            <xsl:call-template name="invoice" >
                <xsl:with-param name="idInvoice" select="@invoice"></xsl:with-param>
            </xsl:call-template>
            </li>
            <li>Si ceva avcolo</li>
        </ul>
    </xsl:template>
    <xsl:template name="invoice" match="table/invioces/invoice[@id=@idInvoice]">
        <xsl:param name="idInvoice"></xsl:param>
        <p>Found something</p>
        <h2><xsl:value-of select="@value" /></h2>
    </xsl:template>
</xsl:stylesheet>

So what I want to do is call a template based on an attribute from a node, display the data and continue to the next node.

IS this possible?

  • 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-30T12:15:26+00:00Added an answer on May 30, 2026 at 12:15 pm

    You can use the current() function to refer to the current context-node. But to do this, you need to select the nodes when calling the template or before:

    <xsl:template name="cost">
        ...
        <xsl:for-each match="/table/invoices/invoice[@id=current()/@invoice]">
            <xsl:call-template name="invoice"/>
        </xsl:for-each>
        ...
    </xsl:template>
    
    • @id refers to the id= attribute of the selected <invoice>.
    • current()/@invoice refers to the invoice= attribute of the context <cost>.

    It is often easier to use <xsl:apply-templates> instead of <xsl:for-each> + <xsl:call-template>, but you would have to rewrite the template to use match= instead of name=.

    <xsl:template match="cost">
        ...
        <xsl:apply-templates match="/table/invoices/invoice[@id=current()/@invoice]"/>
        ...
    </xsl:template>
    
    <xsl:template match="invoice">
        ...
    </xsl:template>
    

    If you need to use a tag-name multiple times, you can use modes:

    <xsl:template match="cost">
        ...
        <xsl:apply-templates match="/table/invoices/invoice[@id=current()/@invoice]"
                             mode="cost-invoice"/>
        ...
    </xsl:template>
    
    <xsl:template mode="cost-invoice" match="invoice">
        ...
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that contains tasks and I want to give these an
I have a MySQL table that contains many rows. The table structure is as
I have a table with navigation that joins back on its self using ParentId.
I have a procedure where customers trigger a calculation that fills a table with
I have table that I insert data with following query (from c# code): INSERT
I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45
I have a table that got into the db_owner schema, and I need it
I have a table that has redundant data and I'm trying to identify all
I have a table that records a sequence of actions with a field that
I have a table that is created in a DataList in ASP.Net. This table

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.