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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:29:23+00:00 2026-05-15T23:29:23+00:00

Just a quick question. I have one XML and I was hoping to tranform

  • 0

Just a quick question. I have one XML and I was hoping to tranform only a section of it without changing anything else. Here is a quick example of what I am looking to do:

Input:

<?xml version="1.0" encoding="UTF-8"?>
<dita xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../xsd/ditabase.xsd">
    <topic id="abc">
        <title>Sample XML</title>
        <body>
         <section id="a">
            <p> Hello section A </p>
         </section>
         <section id="b">
            <p> General Content </p>
         </section>
         <section id="c">
            <p> Hi thank you for coming from $state </p>
         </section>
        </body>
    </topic>
</dita>

Output

<?xml version="1.0" encoding="UTF-8"?>
<dita xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../xsd/ditabase.xsd">
    <topic id="abc">
        <title>Sample XML</title>
        <body>
         <section id="a">
            <p> Hello section A </p>
         </section>
         <section id="b">
            <p> General Content </p>
         </section>
         <section id="c" audience = "WA">
            <p> Hi thank you for coming from WA </p>
         </section>
             <section id="c" audience = NY">
            <p> Hi thank you for coming from NY </p>
         </section>
             <section id="c" audience = "AL">
            <p> Hi thank you for coming from AL </p>
         </section>
             <section id="c" audience = "GA">
            <p> Hi thank you for coming from GA </p>
         </section>
            ...
            <!--Continue for the rest of the states--> 
            ...
        </body>
    </topic>
</dita>

I am using the XALAN processor if that could help. Thanks a lot in advance 😀

  • 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-15T23:29:24+00:00Added an answer on May 15, 2026 at 11:29 pm

    I propose that you change a little bit the format of the XML to make the solurion simpler:

    Instead of:

    <p> Hi thank you for coming from $state </p>
    

    use:

    <p> Hi thank you for coming from <state/> </p>
    

    For this format, the following transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:my="my:my"
     >
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <my:states>
       <state name="WA"/>
       <state name="NY"/>
       <state name="AL"/>
       <state name="GA"/>
     </my:states>
    
     <xsl:variable name="vStates" select="document('')/*/my:states/*"/>
    
     <xsl:template match="node()|@*">
      <xsl:param name="pState"/>
      <xsl:copy>
       <xsl:apply-templates select="node()|@*">
        <xsl:with-param name="pState" select="$pState"/>
       </xsl:apply-templates>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="section[descendant::state]">
       <xsl:variable name="vSect" select="."/>
    
       <xsl:for-each select="$vStates">
         <xsl:apply-templates select="$vSect" mode="generate">
           <xsl:with-param name="pState" select="@name"/>
         </xsl:apply-templates>
       </xsl:for-each>
     </xsl:template>
    
     <xsl:template match="section" mode="generate">
      <xsl:param name="pState"/>
    
      <xsl:copy>
       <xsl:copy-of select="@*"/>
       <xsl:attribute name="audience">
        <xsl:value-of select="$pState"/>
       </xsl:attribute>
       <xsl:apply-templates>
        <xsl:with-param name="pState" select="$pState"/>
       </xsl:apply-templates>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="state">
      <xsl:param name="pState"/>
      <xsl:value-of select="$pState"/>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the (slightly modified) provided XML document:

    <dita xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../xsd/ditabase.xsd">
        <topic id="abc">
            <title>Sample XML</title>
            <body>
             <section id="a">
                <p> Hello section A </p>
             </section>
             <section id="b">
                <p> General Content </p>
             </section>
             <section id="c">
                <p> Hi thank you for coming from <state/> </p>
             </section>
            </body>
        </topic>
    </dita>
    

    produces the wanted, correct result:

    <dita xsi:noNamespaceSchemaLocation="../../../xsd/ditabase.xsd" xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <topic id="abc">
            <title>Sample XML</title>
            <body>
             <section id="a">
                <p> Hello section A </p>
             </section>
             <section id="b">
                <p> General Content </p>
             </section>
             <section id="c" audience="WA">
                <p> Hi thank you for coming from WA </p>
             </section>
    <section id="c" audience="NY">
                <p> Hi thank you for coming from NY </p>
             </section>
    <section id="c" audience="AL">
                <p> Hi thank you for coming from AL </p>
             </section>
    <section id="c" audience="GA">
                <p> Hi thank you for coming from GA </p>
             </section>
            </body>
        </topic>
    </dita>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just a quick question I have an array with only one object in it
Just a quick question here. I have a program in which I need to
Just a quick newbie question here. I have a method that calculates a value
Hi guys I just have one quick question: what happens when an insert statement
A quick question here: is it faster to load a large XML file (just
I just have what I'm sure is a very easy and quick question here...
Quick question, hopefully I am just missing something simple. Ok I have one class
Just a quick question, I have a figure which contain an image and a
Just a quick question. I don't use sitefinity and I don't currently have access
Hi just a quick question, I have a 30 monitor, and when the IB

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.