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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:16:15+00:00 2026-06-12T09:16:15+00:00

I have started using XSLT just recently and am wondering what the effective difference

  • 0

I have started using XSLT just recently and am wondering what the effective difference is between using <xsl:element> for defining elements vs. just declaring them as literals in the XSLT. For example, lets take a simplified case where I’m converting the contents of a tiny XML document into (x)HTML.

1.I could go with the <xsl:element> way:

<xsl:element name="h1">
    <xsl:value-of select="heading"/>
</xsl:element>

2. Or define the element by hand:

<h1>
    <xsl:value-of select="heading"/>
</h1>

What is the actual difference between these two and if a difference exists, which of them is considered ‘good-style’?

  • 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-12T09:16:15+00:00Added an answer on June 12, 2026 at 9:16 am

    They’re almost identical, the exception being that a literal <h1> element will add to the result tree the namespace nodes that are in scope at that point in the stylesheet, whereas the <xsl:element name="h1"> won’t. What difference this makes to your output depends on exactly what namespace declarations your stylesheet includes and where in the result tree you make use of them, if at all. For example, run against any input XML document the following transform:

    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:foo="http://example.com">
    
      <xsl:output method="xml" indent="yes" />
    
      <xsl:template match="/">
        <root>
          <foo:element1 />
          <foo:element2 />
        </root>
      </xsl:template>
    </xsl:stylesheet>
    

    produces the following output (using xsltproc):

    <?xml version="1.0"?>
    <root xmlns:foo="http://example.com">
      <foo:element1/>
      <foo:element2/>
    </root>
    

    but changing the literal <root> in the stylesheet to <xsl:element name="root"> instead produces

    <?xml version="1.0"?>
    <root>
      <foo:element1 xmlns:foo="http://example.com"/>
      <foo:element2 xmlns:foo="http://example.com"/>
    </root>
    

    as the <xsl:element> form doesn’t attach the “foo” namespace node to the generated element. If this matters, and you actually want to copy the stylesheet namespace declarations onto an element you create with <xsl:element> you can do so by nesting something like

    <xsl:copy-of select="document('')/*/namespace::foo" />
    

    directly inside it (using the idiom of document('') which provides access to the stylesheet XML document itself).

    But generally, the main use of <xsl:element> is when the element name is calculated rather than a “compile-time” literal.

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

Sidebar

Related Questions

I have started using SqLite recently, so I am relatively new to it. I
I have started using emacs org-mode recently to maintain my TODO lists. I have
I have started using the protobuf-net lib to communication between some of the programs
I have started using Python for web development recently, it's kinda cool; I have
I have started using django very recently . I am building a service with
I just started on a xml document just for practicing xslt and I have
Recently I have started using ReSharper 6.1, which neatly complements StyleCop which I have
Recently, I have started using Xcode 4 for developing iOS apps. In Xcode intellisense's
I have started using MVC3 recently, I want to know, Can I use MySQL
I have started using valgrind just one day ago as suggested by someone on

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.