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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:51:22+00:00 2026-06-04T23:51:22+00:00

I am trying to write XSLT to transform my XML from one format to

  • 0

I am trying to write XSLT to transform my XML from one format to another. When I apply my .xslt file to the XML file in VS 2010, the output XML structure is created without any problem. But it does not fill in data expected by processing xsl:value-of.

When I use XMLSpy and evaluate the XPath expression, it says no result for the expressions in following XSLT. But when I use node() function at the end of the XPath expression, it shows the value!

  1. What is the correct way of writing XPath?
  2. Does node() and text() kind of functions really necessary everytime to read the element content (when it has no child elements) ? If no, why XmlSpy too does not give result without those functions?
  3. Sometimes (when i change the template match value from “/” to the “ServiceMessage” ) while debugging XSLT, VS 2010 steps into built in template rules. Why is it so? How can I get rid of built in templates in VS 2010?

I have followed w3school tutorial to begin with. I am new to XSLT.

Here is my XML which I want to transform to some other XML format.

<ServiceMessage xmlns="http://requestservice/requests" xmlns:req="http://requestservice/requests/xmlstds">

<TypeOfReq> General </TypeOfReq>
<Details>
   <Id> 123456789 </Id>
   <SenderDetails>
        <Sender id="345"></Sender>
   </SenderDetails>
</Details>

</ServiceMessage>

This is my XSLT

<?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" indent="yes"/>
  <xsl:template match="/">
    <request>
      <requestType>
        <xsl:value-of select="ServiceMessage/TypeOfReq" />
      </requestType>
      <Id>
        <xsl:value-of select="ServiceMessage/Details/Id"/>
      </Id>
      <senderId>
        <xsl:value-of select="ServiceMessage/Details/SenderDetails/Sender/@id"/>
      </senderId>
    </request>

  </xsl:template>



</xsl:stylesheet>
  • 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-04T23:51:24+00:00Added an answer on June 4, 2026 at 11:51 pm

    You have written the xpath correctly from a syntatic point of view. The problem you are actually having is actually to do with namespaces. In your XML you have specified a default namespace

    <ServiceMessage xmlns="http://requestservice/requests">
    

    This means all the child elements, unless otherwise specified, with belong to that namespace. However, in your XSLT, there is no reference to this namepsace at all, and so the XSLT is looking for elements which do not have a namespace specified. This is not the case for your XML.

    For XSLT 1.0, you will need to declare the namespace, like so:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="http://requestservice/requests"> 
    

    You would then explicitly state where it is used for matching the elements

    <xsl:value-of select="s:ServiceMessage/s:TypeOfReq" />
    

    Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="http://requestservice/requests">
       <xsl:output method="xml" indent="yes"/>
       <xsl:template match="/">
          <request>
             <requestType>
                <xsl:value-of select="s:ServiceMessage/s:TypeOfReq"/>
             </requestType>
             <Id>
                <xsl:value-of select="s:ServiceMessage/s:Details/s:Id"/>
             </Id>
             <senderId>
                <xsl:value-of select="s:ServiceMessage/s:Details/s:SenderDetails/s:Sender/@id"/>
             </senderId>
          </request>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your XML, the following is output

    <request xmlns:s="http://requestservice/requests">
       <requestType> General </requestType>
       <Id> 123456789 </Id>
       <senderId>345</senderId>
    </request>
    

    Do note the choice of the letter ‘s’ here is purely arbitrary, it could be anything really.

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

Sidebar

Related Questions

I'm trying convert xml from one format to other using the XslCompiledTransform in c#.
I' trying to write an xml file from Excel VBA using Microsoft XML 6.0.
I'm trying to write an XSLT that will transform an XML document that I
I'm trying to write an XSLT transformation which will replace the value in one
I'm trying to transform some XML-data to HTML with XSLT for my bachelor thesis.
I'm trying to write XSLT to transform a specific web page to JSON. The
I'm trying to write a simple .xslt to process .xml files. But I've been
I have the following line of xml that I'm trying transform using XSLT but
I am trying to write a breadcrumb navigation by using XSL to transform XML.
I'm trying to write an XSLT that organizes an HTML file into different section

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.