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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:22:56+00:00 2026-05-24T20:22:56+00:00

I am using XSLT to transform some provisioning XML into a SOAP request. But

  • 0

I am using XSLT to transform some provisioning XML into a SOAP request. But I am having difficulties finding an approach that does not require full XPATH expressions and still generates valid SOAP XML.

Here is a simplified version of the provisioning XML.

<CreateOrder>
    <client_info>
        <name>John Doe</name>
        <address>
            <street1>1211 Lakeview Dr.</street1>
            <city>New York</city>
            <state>NY</state>
            <country>USA</country>
            <zip>12345</zip>
        </address>
    </client_info>
    <subscriber_number>AAANNNDDDD</subscriber_number>
</CreateOrder>

And here is the simplified XSLT I am using.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" />
    <xsl:template match="/">
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
            <soapenv:Header/>
            <soapenv:Body>
                <DirectoryNumber><xsl:value-of select="CreateOrder/subscriber_number"/></DirectoryNumber>
                <Locale>
                    <xsl:choose>
                        <xsl:when test="CreateOrder/client_info/address/country = 'USA'">
                            <xsl:text>English (US)</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:text>User Defined 1</xsl:text>
                        </xsl:otherwise>
                    </xsl:choose>
                </Locale>
            </soapenv:Body>
        </soapenv:Envelope>
    </xsl:template>
</xsl:stylesheet>

This generates the following XML output – which is what I expected / want. [Note that I had to pretty printed this – my output is actually just a single line wth no line breaks / indents.]

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body>
        <DirectoryNumber>
            AAANNNDDDD
        </DirectoryNumber>
        <Locale>
            English (US)
        </Locale>
    </soapenv:Body>
</soapenv:Envelope>

By playing around, it appears that I need to use <xsl:template match="/"> to match the whole input document, or else I do not get the SOAP XML into the output. Is there some other way of generating a sequence of new XML from the XSLT?

But when the <xsl:template match="/"> is present, I can’t nest other <xsl:template match=..."> elements (for example to match “address”) and so have to use full XPATH node expressions (such as CreateOrder/client_info/address/country) in the tests. This works but is not particularly elegant, and is somewhat error prone for a real world longer example. Is there a better way of doing this?

  • 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-24T20:22:57+00:00Added an answer on May 24, 2026 at 8:22 pm

    Templates don’t nest. You achieve what you want with <xsl:apply-templates.../> at the appropriate places in your templates. In your simple example there’s no getting around having to specify the path, but in a larger, more complex stylesheet you could have many reusable templates.

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
      <xsl:output method="xml" indent="yes"/>
      <xsl:template match="/">
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
          <soapenv:Header/>
          <soapenv:Body>
            <DirectoryNumber><xsl:value-of select="CreateOrder/subscriber_number"/></DirectoryNumber>
            <Locale>
              <xsl:apply-templates select="CreateOrder/client_info/address/country"/>
            </Locale>
          </soapenv:Body>
        </soapenv:Envelope>
      </xsl:template>
    
      <xsl:template match="country">
        <xsl:choose>
          <xsl:when test=". = 'USA'">
            <xsl:text>English (US)</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>User Defined 1</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>
    
    </xsl:stylesheet>
    

    The key to understanding XSLT is to realize that it’s not procedural… your stylesheet is NOT in control. Instead, the XSLT processor is examining each input tag and then searching the stylesheet for a matching template. Once a matching rule is found and applied, processing for that tag is done. If you match /, then the entire document is consumed by that one template. The only way other templates can be invoked is through <xsl:apply-templates select="some xpath"/> which tells the processor to restart the matching process using the nodes selected by “some xpath”. It is extremely common for the first template in a stylesheet to match /.

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

Sidebar

Related Questions

I'm trying to transform some XML into HTML using XSLT . Problem: I can't
I’ve been trying to transform some simple XML into another simple XML using XSLT.
I'm using XSLT to transform from one format of XML into another but I
I'm using the javax.xml.transform.Transformer class to perform some XSLT translations, like so: TransformerFactory factory
i want to transform some xml into HTML that has the following format: <TR><TD>
I'm using an XsltCompiledTransform to transform some XML into a fragment of HTML (not
I need to transform one XML document into another using XSLT (for now from
I transform some RSS XML feeds using XSLT. Basically there are two types I
I am using XSLT to transform a XML into a html/php file. In this
I'm using XSLT 1.0 to transform some XML. I'm not quite sure the best

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.