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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:49:14+00:00 2026-06-08T13:49:14+00:00

Definitely I will never find success thinking in XSLT… Here is what I have:

  • 0

Definitely I will never find success thinking in XSLT…

Here is what I have:

   <par font="Arial" size="24">text 24</par>
   <par font="Arial" size="12">text 12</par>
   <par font="Times New Roman" size="12">text times 12</par>

And here is what I want:

   <font style="font-family:Arial"><font style="font-size:24">text 24</font></font>
   <font style="font-family:Arial"><font style="font-size:12">text 12</font></font>
   <font style="font-family:Times New Roman"><font style="font-size:12">text times 12</font></font>

Of course, something like this is good as well, but for me this solution seems more complicated:

<font style="font-family:Arial;font-size:24">text 24</font>
<font style="font-family:Arial;font-size:12">text 12</font>
<font style="font-family:Times New Roman;font-size:12">text times 12</font>

I think (but I may be wrong) I will have to specify some code for each size and each font. This is not a problem because there are only few sizes and fonts available in my xml.

Many many thanks for your help, I start loosing my hair trying to do it by myself…

  • 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-08T13:49:16+00:00Added an answer on June 8, 2026 at 1:49 pm

    You could do something like this:

    XML Input (modified to be well-formed)

    <doc>
        <par font="Arial" size="24">text 24</par>
        <par font="Arial" size="12">text 12</par>
        <par font="Times New Roman" size="12">text times 12</par>   
    </doc>
    

    XSLT 1.0

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="doc">
            <html>
                <xsl:apply-templates/>
            </html>
        </xsl:template>
    
        <xsl:template match="par">
            <font>
                <xsl:attribute name="style">
                    <xsl:apply-templates select="@*"/>
                </xsl:attribute>
                <xsl:apply-templates select="node()"/>
            </font>
        </xsl:template>
    
        <xsl:template match="par/@size">
            <xsl:value-of select="concat('font-size: ',.,';')"/>
        </xsl:template>
        <xsl:template match="par/@font">
            <xsl:value-of select="concat('font-family: ',.,';')"/>
        </xsl:template>
    
    </xsl:stylesheet>
    

    Output

    <html>
       <font style="font-family: Arial;font-size: 24;">text 24</font>
       <font style="font-family: Arial;font-size: 12;">text 12</font>
       <font style="font-family: Times New Roman;font-size: 12;">text times 12</font>
    </html>
    

    Also, you can change the match="par" to match="par[@font or @size]" if you only want to output <font> if it has a font or size attribute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen similar questions (ex here and here ) but never seen a
I have categories with (infinite possible levels but will definitely be kept under a
I updated to Xcode 4.5 and am working with iOS6--a mistake I will definitely
In the example I'm thinking of I have about 4 lines of code that
I've definitely got JDK 1.6.0 installed in C:\Program Files\Java\jdk1.6.0_35 , but it never seems
I'm building a Java program that will automatically run a hundred or so tests.
Ok, I got a strange one here and I want to know if any
I have two distinct modules that can be used independently, but Module2 is dependent
I have a java web app that makes back-end use of a third-party web
Company's Fiscal Year: July 1 - June 30 I have a query where I

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.