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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:29:21+00:00 2026-05-25T22:29:21+00:00

I’m just trying to create an example XML file with an XSL style sheet.

  • 0

I’m just trying to create an example XML file with an XSL style sheet. The problem is, when i parse the two files, i get a strange output.

here is the XML:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="mySchema.xsl"?>
<Artists>
  <Artist>
    <BandName>The Cure</BandName>
    <Albums>
      <Album>
        <AlbumTitle>Disintegration</AlbumTitle>
        <Tracks>
          <track>
            <Title>Plain Song</Title>
            <Order>1</Order>
            <Lenght>
              <min>5</min>
              <sec>12</sec>
            </Lenght>
          </track>
          <track>
            <Title>Pictures Of You</Title>
            <Order>2</Order>
            <Lenght>
              <min>7</min>
              <sec>24</sec>
            </Lenght>
          </track>
        </Tracks>
      </Album>
      <Album>
        <AlbumTitle>Wish</AlbumTitle>
        <Tracks>
          <track>
            <Title>A Letter To Elise</Title>
            <Order>4</Order>
            <Lenght>
              <min>5</min>
              <sec>14</sec>
            </Lenght>
          </track>
          <track>
            <Title>From the Edge of the Deep Green Sea</Title>
            <Order>2</Order>
            <Lenght>
              <min>7</min>
              <sec>45</sec>
            </Lenght>
          </track>
        </Tracks>
      </Album>
    </Albums>
  </Artist>

  <Artist>
    <BandName>The Pogues</BandName>
    <Albums>
      <Album>
        <AlbumTitle>If I Should Fall from Grace with God</AlbumTitle>
        <Tracks>
          <track>
            <Title>Fairytale of New York</Title>
            <Order>1</Order>
            <Lenght>
              <min>2</min>
              <sec>20</sec>
            </Lenght>
          </track>
          <track>
            <Title>Sit Down by the Fire</Title>
            <Order>13</Order>
            <Lenght>
              <min>4</min>
              <sec>10</sec>
            </Lenght>
          </track>
        </Tracks>
      </Album>
      <Album>
        <AlbumTitle>Peace And Love </AlbumTitle>
        <Tracks>
          <track>
            <Title>Young Ned Of The Hill</Title>
            <Order>3</Order>
            <Lenght>
              <min>2</min>
              <sec>45</sec>
            </Lenght>
          </track>
          <track>
            <Title>Boat Train</Title>
            <Order>11</Order>
            <Lenght>
              <min>2</min>
              <sec>40</sec>
            </Lenght>
          </track>
        </Tracks>
      </Album>
    </Albums>
  </Artist>
</Artists>

and here is the XSLT file:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="Artist">
    <html>
      <body>
        <xsl:apply-templates select="BandName"/>
        <br></br>
      </body>
    </html>

  </xsl:template>
  <xsl:template match="BandName">
    <b>Found a band!</b>
  </xsl:template>
</xsl:stylesheet>

When i render the two, using visual studio ide, i can see how the XML file transformed to XHTML. the output looks like this:

<?xml version="1.0" encoding="utf-8"?>
  <html><body><b>Found a band!</b><br /></body></html>

  <html><body><b>Found a band!</b><br /></body></html>

When i look at this in the browser, its fine, but i’m not happy how the < html >< body >< /body >< /html > is displayed more that once. What am i doing wrong?

thanks
jason

  • 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-05-25T22:29:22+00:00Added an answer on May 25, 2026 at 10:29 pm

    Your match="Artist" template is getting applied twice because there are two Artist in your source document. This is what’s resulting in two html elements in the result tree.

    Try using this slightly modified version of your stylesheet:

    <?xml version="1.0" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="Artists">
        <html>
          <body>
            <xsl:apply-templates select="Artist"/>
            <br></br>
          </body>
        </html>    
      </xsl:template>
    
      <xsl:template match="Artist">
        <xsl:apply-templates select="BandName"/>
      </xsl:template>
    
      <xsl:template match="BandName">
        <b>Found a band!</b>
      </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an XML file, the creators of it stuck in a bunch social
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into

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.