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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:41:38+00:00 2026-06-12T03:41:38+00:00

I’ve basically got an XML input structure like this: … <box type=rectangle class=someOriginalClass> <background

  • 0

I’ve basically got an XML input structure like this:

...
<box type="rectangle" class="someOriginalClass">
    <background bgtype="solid" />
    <animation order="3" />
    ... children
</box>

and would like to transform it to

<div class="someOriginalClass rectangle solid animated order3">
    ...children
</div>

Note that neither background nor animation need to be there, and this is a reduced example, meaning that there could be more properties like these, with more attributes.
As well, animation and background are reused elsewhere.

My XSLT code so far is:

<xsl:template match="box">
    <div class="{@someOldClass} {@type}">
        <xsl:apply-templates select="./*" />
    </div>
</xsl:template>

<xsl:template match="background">
    <xsl:attribute name="class">
      <xsl:value-of select="@bgtype"/>
    </xsl:attribute>
</xsl:template>

<xsl:template match="animation">
    <xsl:attribute name="class">
      animated order<xsl:value-of select="@order"/>
    </xsl:attribute>
</xsl:template>

The problem with this code is that each template overrides the class attribute completely, dismissing already contained classes.

To solve this, I’ve tried:

a) rewriting old classes => value-of only gets input XML class (someOldClass)

<xsl:template match="animation">
    <xsl:attribute name="class">
      <xsl:value-of select="../@class"/>
      animated order<xsl:value-of select="@order"/>
    </xsl:attribute>
</xsl:template>

b) instead passing changes between templates with params => only one time, one way

<xsl:template match="box">
    <div class="{@someOldClass} {@type}">
        <xsl:apply-templates select="./*">
            <xsl:with-param name="class" select="concat(@someOldClass,' ',@type)"/>
        </xml:apply-templates>
    </div>
</xsl:template>

<xsl:template match="animation">
    <xsl:param name="class"/>
    <xsl:attribute name="class">
      <xsl:value-of select="$class"/>
      animated order<xsl:value-of select="@order"/>
    </xsl:attribute>
</xsl:template>

You see, I’m lacking a solution that will work with any number of class updates, with minimal redundancy.
BTW, I’m an XSLT beginner, so maybe there’s some predestined feature that I’ve simply not yet come across.

Any ideas?

  • 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-12T03:41:39+00:00Added an answer on June 12, 2026 at 3:41 am

    I’ve used this before. I’m not sure what your XML looks like but this may help get you on the right path.

    <xsl:template match="box">
    <xsl:param name="boxType" />
    <li>
        <xsl:variable name="boxClass">
            <xsl:value-of select="$boxType"/>
            <xsl:if test="@class1 = 1"> class1</xsl:if>
            <xsl:if test="@class2 = 1"> class2</xsl:if>
            <xsl:if test="@class3 = 1"> class3</xsl:if>
            <xsl:if test="@class4 = 1"> class4</xsl:if>
            <xsl:if test="@last = 1"> lnLast</xsl:if>
        </xsl:variable>
        <xsl:attribute name="class">
            <xsl:value-of select="$boxClass"/>
        </xsl:attribute>
    </li>
    </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 string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters

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.