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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:07:52+00:00 2026-06-11T20:07:52+00:00

XML data file <?xml version=1.0 encoding=utf-8?> <page> <tab dim=70> <tab dim=50> alpha </tab> <tab

  • 0

XML data file

<?xml version="1.0" encoding="utf-8"?>
<page>
    <tab dim="70">

        <tab dim="50">
        alpha

        </tab>
        <tab dim="50">
        alpha

        </tab>

    </tab>
    <tab dim="30">
        gama
    </tab>
</page>

XSLT File

<?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="iso-8859-1" indent="yes"/>

<xsl:template match="/">
    <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html&gt;</xsl:text>
    <html>
    <head>
        <title>Title</title>
        <link type="text/css" href="/css/framework.css" rel="stylesheet"/>

    </head>
    <body>
    <div id="page-base">
        <xsl:for-each select="//tab">
        <div class="wrapper tab">
            <xsl:attribute name="style"> 
                width:<xsl:value-of select="@dim" />%;
                min-width:<xsl:value-of select="@dim" />%;
                max-width:<xsl:value-of select="@dim" />%;
            </xsl:attribute>
            <xsl:value-of select="." />
        </div>
        </xsl:for-each>
    </div>
    </body>
    </html>
</xsl:template>

</xsl:stylesheet>

Ouput

<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" href="/css/framework.css" type="text/css">
</head>
<body>
<div id="page-base">
 <div class="wrapper tab" style=" width:70%; min-width:70%; max-width:70%; ">
   alpha alpha   
 </div>
 <div class="wrapper tab" style=" width:50%; min-width:50%; max-width:50%; "> alpha </div>
 <div class="wrapper tab" style=" width:50%; min-width:50%; max-width:50%; "> alpha </div>
 <div class="wrapper tab" style=" width:30%; min-width:30%; max-width:30%; "> gama </div>
</div>
</body>

Desired output

<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" href="/css/framework.css" type="text/css">
</head>
<body>
<div id="page-base">
 <div class="wrapper tab" style=" width:70%; min-width:70%; max-width:70%; ">
  <div class="wrapper tab" style=" width:50%; min-width:50%; max-width:50%; "> alpha </div>
  <div class="wrapper tab" style=" width:50%; min-width:50%; max-width:50%; "> alpha </div>
 </div>
 <div class="wrapper tab" style=" width:30%; min-width:30%; max-width:30%; "> gama </div>
</div>
</body>
</html>

  • 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-11T20:07:53+00:00Added an answer on June 11, 2026 at 8:07 pm

    The key is not to use <xsl:for-each> at all. Use template matching instead.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" indent="yes" />
      <xsl:strip-space elements="*" />
    
      <xsl:template match="/">
        <html>
          <head>
            <title>Title</title>
            <link type="text/css" href="/css/framework.css" rel="stylesheet"/>
          </head>
          <body>
            <xsl:apply-templates />
          </body>
        </html>
      </xsl:template>
    
      <xsl:template match="page">
        <div id="page-base">
          <xsl:apply-templates />
        </div>
      </xsl:template>
    
      <xsl:template match="tab">
        <div class="wrapper tab" style="width:{@dim}%; min-width:{@dim}%; max-width:{@dim}%;">
          <xsl:apply-templates />
        </div>
      </xsl:template>
    </xsl:stylesheet>
    

    Result: (also see http://xsltransform.net/gWmuiK6)

    <html>
       <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
          <title>Title</title>
          <link type="text/css" href="/css/framework.css" rel="stylesheet">
       </head>
       <body>
          <div id="page-base">
             <div class="wrapper tab" style="width:70%; min-width:70%; max-width:70%;">
                <div class="wrapper tab" style="width:50%; min-width:50%; max-width:50%;">
                   alpha
    
    
                </div>
                <div class="wrapper tab" style="width:50%; min-width:50%; max-width:50%;">
                   alpha
    
    
                </div>
             </div>
             <div class="wrapper tab" style="width:30%; min-width:30%; max-width:30%;">
                gama
    
             </div>
          </div>
       </body>
    </html>
    

    To get rid of the white-space in the output, all you need to do is to add another template:

    <xsl:template match="tab/text()">
      <xsl:value-of select="normalize-space()" />
    </xsl:template>
    

    There are specific cases where <xsl:for-each> is the right thing to use. This is not one of them.

    Whenever you feel inclined to use <xsl:for-each> you should stop and think. In the vast majority of cases <xsl:apply-templates> is what you really want.

    Use <xsl:for-each> only if you find a compelling reason against <xsl:apply-templates>. If you can’t think of one such reason, then there probably is none.


    To output nodes that appear in the input without changing them, add the identity template:

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

    To mute nodes that you do not want in the output, add an empty template:

    <xsl:template match="node/to/match" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How build ASP.NET MVC View page from XML file? <?xml version=1.0 encoding=utf-8 ?> -
Imagine you have a data.xml file: <?xml version=1.0 encoding=UTF-8 ?> <root> <item>value1</item> <item>value2</item> <item>value3</item>
I have got below xml format file called ResourceData.xml . <?xml version=1.0 encoding=utf-8 ?>
<?xml version=1.0 encoding=utf-8 ?> <user> <username>prince</username> <password>user1</password> </user> This is my xml file name
An example XML file is this: <?xml version=1.0 encoding=UTF-8?> <game> <name>bomber</name> <behaviors-used> <behavior id=Bullet
Here's my application-security.xml file: <?xml version=1.0 encoding=UTF-8?> <!-- - Sample namespace-based configuration - -
I need to get data from xml file <?xml version=1.0?> <xml> <User> <Agent> <id>cr4523</id>
I want to read this xml file using Id on <page> tag. <?xml version=1.0
I have document <?xml version=1.0 encoding=utf-8 ?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd>
I have an xml data file and I want to populate a listview in

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.