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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:32:31+00:00 2026-06-18T10:32:31+00:00

I have an xml like this: <span reference=1>Reference Text 1</span> <term reference=2>Reference Text 2</term>

  • 0

I have an xml like this:

<span reference="1">Reference Text 1</span>
<term reference="2">Reference Text 2</term>

And I need it to become this:

<span class="referenceText">Reference Text 1</span> <a href="1">[1]</a>
<i>Reference Text 2</i> <a href="2">[2]</a>

So, basically, if the element with the reference attribute is a span, we just leave it as is, adding class="referenceText". If, however it is any other element, then we should also apply templates created for this element. That’s why <term> should become <i> – I have a template for it:

<xsl:template match="term">
  <i><xsl:apply-templates select="@* |node()"/></i>
</xsl:template>

For the transformation of all elements with a reference attribute I have this template:

<xsl:template match="*[@reference]">

  <xsl:param name="href" select="./@reference"/>

  <xsl:choose>
    <xsl:when test="name() = 'span'">
      <span class="referenceText">
        <xsl:value-of select="."/>
      </span>
    </xsl:when>
    <xsl:otherwise>
      <xsl:element name="{name()}">
        <xsl:value-of select="."/>
      </xsl:element>
    </xsl:otherwise>
  </xsl:choose>

  <xsl:text> </xsl:text><a href="#{$href}">[<xsl:value-of select="./@href"/>]</a>

</xsl:template>

Unfortunately, this results in the following output:

<span class="referenceText">Reference Text 1</span> <a href="1">[1]</a>
<term>Reference Text 2</term> <a href="2">[2]</a>

So, <term> is not converted into <i>. It looks like I need some sort of recursion to re-apply the templates to what’s been generated, but I can’t come up with anything.

  • 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-18T10:32:32+00:00Added an answer on June 18, 2026 at 10:32 am

    If you’re using XSLT 1.0, you can capture the output in a variable and then use the exslt:node-set function to apply templates to the variable. Try to avoid infinite recursion, though 🙂

    <xsl:variable name="foo">
    ...
    </xsl:variable>
    <xsl:apply-templates select="exslt:node-set($foo)"/>
    

    (EDIT: incorporating additional comments relevant to this answer)

    In order to use an EXSLT extension, the first step is to declare its namespace. The EXSLT project website recommends doing so on your <xsl:stylesheet> node:

    The first step to using the extensions described in EXSLT is to define the relevant namespace for the EXSLT module. You should declare the namespace on the xsl:stylesheet element in your stylesheet.

    <xsl:stylesheet xmlns:exslt="http://exslt.org/common">
      //...
    </xsl:stylesheet>
    

    In addition, the extension-element-prefixes attribute can be used to prevent the extensions namespaces from being added to the resulting document:

    <xsl:stylesheet xmlns:exslt="http://exslt.org/common" extension-element-prefixes="exslt">
      //...
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my XML like this <P style=TEXT-ALIGN: center; MARGIN: 0pt> <SPAN style=FONT-FAMILY: 'Times
I have xml like this: <rule> <word>I</word> <word>need</word> <word>more</word> <marker> <word>money</word> </marker> <word>now</word> </rule>
Let's suppose I have xml like this one: <Server Active=No> <Url>http://some.url</Url> </Server> C# class
I have an XML like this: <EXP> <TITLES> <SUBTITLE CL=AXT4 FL=1 NB=Text 1/> </TITLES>
If I have some xml like this: <mynode> <mysubnode> <mysubsubnode>hello world</mysubsubnode> some more text
I have some XHTML (but really any XML will do) like this: <h1> Hello<span
I have XML like this: <Artist name=Syd Mead id=3412 ntrack=28 pop=8/> Which I need
I have XML like this: <a> <b> <c>some text here</c> </b> </a> <a> <b>
I have xml like this XElement xe = <root> <mynode> Text with link <a
I have XML like this: <article> <title>Article 1 title</title> <text>Lorem ipsum...</text> <image>http://example.com/img_01.jpg</image> </article> <article>

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.