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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:18:10+00:00 2026-06-02T06:18:10+00:00

I have separated certain statements to be applied on a specific element in a

  • 0

I have separated certain statements to be applied on a specific element in a separate template.
The element is processed in one template, which contains a statement <xsl:apply-templates/>.
Is there a way to have an element just processed in the first template, to be re-processed in the second (non-named) template?
Of course I know that I could use a named template and call that from the first template, but I am just wondering whether it could be done like this.
To give you something to work with, here’s a heavily simplified model of the stuff I am working on.
I have an html input file containing a table:

<?xml version="1.0" encoding="UTF-8"?>
<table>
    <tbody>
        <tr>
            <td>content</td>
            <td></td>
            <td/>
        </tr>
    </tbody>
</table>

I wish to have a block element inside each td element that encloses the td string content if there is one, or is empty when the td element itself is empty. I tried the following (note again that I do not wish to do major changes in the first template!):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="*">
        <xsl:copy>
            <xsl:attribute name="test"><xsl:value-of select="local-name()"/></xsl:attribute>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="td/text()">
        <block><xsl:value-of select="."/></block>
    </xsl:template>
</xsl:stylesheet>

Where the added attribute is just a modelled example of the stuff that is being done in the first template.

which gives as output

<?xml version="1.0" encoding="UTF-8"?>
<table test="table">
    <tbody test="tbody">
        <tr test="tr">
            <td test="td">
                <block>content</block>
            </td>
            <td test="td"/>
            <td test="td"/>
        </tr>
    </tbody>
</table>

and I wish to get

<?xml version="1.0" encoding="UTF-8"?>
<table test="table">
    <tbody test="tbody">
        <tr test="tr">
            <td test="td">
                <block>content</block>
            </td>
            <td test="td">
                <block/>
            </td>
            <td test="td">
                <block/>
            </td>
        </tr>
    </tbody>
</table>

It is clear why it did not work: there is no text node in the empty td elements, so these are not matched by the second template’s Xpath expression.
So I started thinking about ways to re-process the td elements itself by a second template. Of course, I can not use match="td[some condition]" because then the first template will not be applied.
And I can also not use match= "self::td" because the self axis is not allowed in template match attributes (except in conditions of course), or rather, it needs a current node which you don’t have yet when starting to match.
So is there a suitable Xpath expression available for the second template that will give me what I want?
Or is there another simple way to trigger another (non-named) template for an element just processed in one template?
Note: I am not looking for simple updates on the second template, that add the attribute there. I wish the first template to add the attribute, and the second to add the block elements.

  • 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-02T06:18:12+00:00Added an answer on June 2, 2026 at 6:18 am

    Try adding another “moded” template. You should be able to use xsl:apply-templates with the mode.

    Example xsl:template:

    <xsl:template match="td" mode="test">
      <bar>test</bar>
    </xsl:template>
    

    Example xsl:apply-templates:

    <xsl:template match="td">
      <foo><xsl:apply-templates select="ancestor-or-self::td" mode="test"/></foo>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a certain TABLE, I have a VARTEXT field which includes comma-separated values of
I have Text file that contains data separated with a comma , . How
I have certain algorithm need to implement. Basically the rules are: The first whitespace-separated
I have a .txt file which has about 500k entries, each separated by new
I have been able to extract certain lines from a large tab-separated text file
I have a certain POJO which needs to be persisted on a database, current
I have a viewmodel that needs to display a certain IEnumerable field as semicolon-separated
In my application I have a form, which elements are named using a certain
I have 5-6 jobs to be done by cron, and i have separated php
I have semicolon-separated .dat file and I want to read that file and store

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.