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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:56:40+00:00 2026-06-18T17:56:40+00:00

I saw an example to transform xml to another xml using JSTL. But in

  • 0

I saw an example to transform xml to another xml using JSTL. But in that example they hard coded the attribute value. Please see the bellow example

Input XML

country isocode="de" pk="8796093055010" uri="http://localhost:9001/ws410/rest/countries/de">
        <comments/>
        <creationtime>2011-08-03T21:53:35.624+05:30</creationtime>
        <dimVals/>
        <modifiedtime>2011-08-03T22:05:10.111+05:30</modifiedtime>
        <active>true</active>
        <name>Germany</name>
        <regions>
              <region isocode="DE-BW" pk="8796093055011" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-BW"/>
              <region isocode="DE-BY" pk="8796093087779" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-BY"/>
              <region isocode="DE-BE" pk="8796093120547" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-BE"/>
              <region isocode="DE-BR" pk="8796093153315" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-BR"/>
              <region isocode="DE-HB" pk="8796093186083" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-HB"/>
              <region isocode="DE-HH" pk="8796093218851" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-HH"/>
              <region isocode="DE-HE" pk="8796093251619" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-HE"/>
              <region isocode="DE-MV" pk="8796093284387" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-MV"/>
              <region isocode="DE-NI" pk="8796093317155" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-NI"/>
              <region isocode="DE-NW" pk="8796093349923" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-NW"/>
              <region isocode="DE-RP" pk="8796093382691" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-RP"/>
              <region isocode="DE-SL" pk="8796093415459" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-SL"/>
              <region isocode="DE-ST" pk="8796093448227" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-ST"/>
              <region isocode="DE-SN" pk="8796093480995" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-SN"/>
              <region isocode="DE-SH" pk="8796093513763" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-SH"/>
              <region isocode="DE-TH" pk="8796093546531" uri="http://localhost:9001/ws410/rest/countries/de/regions/DE-TH"/>
        </regions>
        <zones>
            <zone code="de" pk="8796093056179" uri="http://localhost:9001/ws410/rest/zones/de"/>
        </zones>
</country>

XSLT

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

    <xsl:template match="/">
        <xsl:apply-templates select="/country/regions" />
    </xsl:template>

    <xsl:template match="regions">
        <RECORDS>
            <xsl:for-each select="region">
                <RECORD>
                    <PROP name="isocode">
                        <PVAL>
                            <xsl:value-of select="@isocode" />
                        </PVAL>
                    </PROP>
                    <PROP name="pk">
                        <PVAL>
                            <xsl:value-of select="@pk" />
                        </PVAL>
                    </PROP>
                    <PROP name="uri">
                        <PVAL>
                            <xsl:value-of select="@uri" />
                        </PVAL>
                    </PROP>
                </RECORD>
            </xsl:for-each>
        </RECORDS>
    </xsl:template>
</xsl:stylesheet>

Output XML

<?xml version="1.0" encoding="UTF-8"?>
<RECORDS>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-BW</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093055011</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-BW</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-BY</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093087779</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-BY</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-BE</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093120547</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-BE</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-BR</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093153315</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-BR</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-HB</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093186083</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-HB</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-HH</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093218851</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-HH</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-HE</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093251619</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-HE</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-MV</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093284387</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-MV</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-NI</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093317155</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-NI</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-NW</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093349923</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-NW</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-RP</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093382691</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-RP</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-SL</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093415459</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-SL</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-ST</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093448227</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-ST</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-SN</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093480995</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-SN</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-SH</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093513763</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-SH</PVAL>
        </PROP>
    </RECORD>
    <RECORD>
        <PROP name="isocode">
            <PVAL>DE-TH</PVAL>
        </PROP>
        <PROP name="pk">
            <PVAL>8796093546531</PVAL>
        </PROP>
        <PROP name="uri">
            <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-TH</PVAL>
        </PROP>
    </RECORD>
</RECORDS>

In this output xml I am creating many RECORD sub elements. My problem is I want to transform the PROB name attribute () value without hardcoding. I need to read the reagion element attributtes from input xml and transform that value to output xml. Please help me to find the solution.
Thank you…

  • 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-18T17:56:42+00:00Added an answer on June 18, 2026 at 5:56 pm

    I believe this is what you are looking for:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
      <xsl:template match="/">
        <xsl:apply-templates select="/country/regions" />
      </xsl:template>
    
      <xsl:template match="regions">
        <RECORDS>
          <xsl:apply-templates select="region" />
        </RECORDS>
      </xsl:template>
    
      <xsl:template match="region">
        <RECORD>
          <xsl:apply-templates select="@*" />
        </RECORD>
      </xsl:template>
    
      <xsl:template match="region/@*">
        <PROP name="{name()}">
          <PVAL>
            <xsl:value-of select="." />
          </PVAL>
        </PROP>
      </xsl:template>
    </xsl:stylesheet>
    

    When run on your input XML, this produces the output:

    <RECORDS>
      <RECORD>
        <PROP name="isocode">
          <PVAL>DE-BW</PVAL>
        </PROP>
        <PROP name="pk">
          <PVAL>8796093055011</PVAL>
        </PROP>
        <PROP name="uri">
          <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-BW</PVAL>
        </PROP>
      </RECORD>
      <RECORD>
        <PROP name="isocode">
          <PVAL>DE-BY</PVAL>
        </PROP>
        <PROP name="pk">
          <PVAL>8796093087779</PVAL>
        </PROP>
        <PROP name="uri">
          <PVAL>http://localhost:9001/ws410/rest/countries/de/regions/DE-BY</PVAL>
        </PROP>
      </RECORD>
      <!-- (Several more similar records) -->
    </RECORDS>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
I saw a Java example that had a main method labeled as synchronized, calling
I saw some websites that (for example): if you want to view your message
I saw an example here and checked how it works but i got an
I saw an example of using the function: delete in cpp and I didn't
I saw the example with Flower an MyGarden, but when I try to make
I saw an example that uses the following to create a point that will
I saw an example of using Expression Builders, and creating your own Custom Expression
i saw many example of Fluent style api development but some time i saw
I saw an example in the book The Rails 3 Way that says redirect_to

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.