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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:04:42+00:00 2026-05-27T23:04:42+00:00

Seems like I never stop banging my head with this =/ And believe me

  • 0

Seems like I never stop banging my head with this =/
And believe me I’m not lazy because I’m asking here .:)

What I’m trying to do now is that I want to give my XML file a new root element.

So my output should be something like this.

<motorpark>
<fordon pris="129900"><name>Honda</name><modellTyp1/></fordon>
    <fordon pris="119000"><name>Nissan</name><modellTyp2/></fordon>
</motorpark>

But I cant seem to point out my template correct.

ether way It prints out my whole XML file, without even read my XSL file
Or I get on every element thats printing out.

This is what I accomplish for the moment with some help from lwburk here on stackoverflow 🙂

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="ad">
<xsl:element name="motorpark">
<xsl:apply-templates select="autoads" mode="ad"/>
</xsl:element>
</xsl:template>
<xsl:template match="ad">
<xsl:element name="fordon">
<xsl:attribute name="pris">
<xsl:copy-of select="price" />
</xsl:attribute>
<xsl:copy-of select="name"/>
<xsl:element name="{concat('modellTyp', type)}">
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

My XML file is looking like this.

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="uppgift2.xsl"?>
<autoads>
    <ad>
        <type>1</type>
        <name>Honda</name>
        <model>XL 1000 V</model>
        <regyear>2001</regyear>
        <price>129900</price>
        <adtext>2001 Honda XL 1000 V, 8.900 km. hög vindruta. Pris 129.900kr,-.  </adtext>
        <addate>20020115</addate>
        <volume>1000</volume>
        <category></category>
    </ad>
    <ad>
        <type>2</type>
        <name>Nissan</name>
        <model>Almera 1.4S</model>
        <regyear>1997</regyear>
        <price>119000</price>
        <adtext>1997 Nissan Almera 1.4S, 5 dörrar, met, 70.000 km. el.spegel/fönster, galv. kaross, c.lås, startspärr, airbag, nedfällb. baks. ABS, ute temp. R/CD, alarm, d.fäste, v.säten, s/v-hj.  EU-godk. full service, servo. Pris 119.000 kr,-.  </adtext>
        <addate>20020118</addate>
        <volume>0</volume>
        <category>5 dörrar</category>
    </ad>
</autoads>
  • 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-27T23:04:42+00:00Added an answer on May 27, 2026 at 11:04 pm

    The following stylesheet produces the desired result:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="/">
            <motorpark>
                <xsl:apply-templates/>
            </motorpark>
        </xsl:template>
        <xsl:template match="ad">
            <fordon pris="{price}">
                <xsl:copy-of select="name"/>
                <xsl:element name="{concat('modellTyp', type)}"/>   
            </fordon>
        </xsl:template>
    </xsl:stylesheet>
    

    Notice that the stylesheet’s size can be greatly reduced by hardcoding element and attribute names when they’re known in advance. xsl:element and xsl:attribute are usually only necessary when producing dynamic content. Also, note that you previously had two templates matching exactly the same element. We’re now matching the root (/) and ad nodes separately.

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

Sidebar

Related Questions

Seems like just yesterday I had this same problem with Play! v1. After trying
Seems like there should be... Right now it just seems like magic that you
Seems like this should be obvious, but how do I send arrow key presses
Seems like this should be simple, but powershell is winning another battle with me.
seems like I'm stuck with jQuery tabs. I'm trying to pass selected tab name
My vertical auto scroll seems to stop erratically at some points, I would like
This seems like it should be a no-brainer, but I can't get a WPF
Seems like i need some help with a project. I have a routine ,
Seems like cuke doesn't show the full error message (at least when problem occurs
Seems like a standard approach for an ioc when given a scenario like (C#

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.