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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:05:46+00:00 2026-05-26T11:05:46+00:00

I’m trying to help a friend solve a computer class take-home quiz. I have

  • 0

I’m trying to help a friend solve a computer class take-home quiz. I have a simple XML file as follows which defines DVD titles I own on my shelf…

<Inventory>
    <DVD>
        <Name>Captain America</Name>
    </DVD>
    <DVD>
        <Name>Green Lantern</Name>
    </DVD>
    <DVD>
        <Name>Thor</Name>
    </DVD>
</Inventory>

Let’s say both “Captain America” and “Thor” are checked-out while “Green Lantern” is still available. I would like to transform the above XML file into the following XML…

<Inventory>
    <DVD>
        <Name>Captain America</Name>
        <Status>Checked-Out</Status>
    </DVD>
    <DVD>
        <Name>Green Lantern</Name>
        <Status>Available</Status>
    </DVD>
    <DVD>
        <Name>Thor</Name>
        <Status>Checked-Out</Status>
    </DVD>
</Inventory>

Can someone share how to utilize XSL to add the Status element to each node? I only have the code snippet below but it copies the same element for all nodes.

<xsl:template match="*">
    <xsl:copy>
        <xsl:copy-of select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="DVD">
    <xsl:copy>
        <xsl:copy-of select="@*|node()"/>
        <Status>Checked-Out</Status>
    </xsl:copy>
</xsl:template>

Thank you very very very much…

  • 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-26T11:05:47+00:00Added an answer on May 26, 2026 at 11:05 am

    What you can do is use an xsl:param to pass the name(s) of the DVD’s that are checked out to your XSL and add the <status> based on that. By using xsl:param, you can pass the value from the command line.

    Here’s an XSLT 2.0 example where the DVD names are pipe delimited in the xsl:param. I use tokenize() in my xsl:template match so that those DVD’s get a status of “Checked-Out”. All of the other DVD’s will get the status of “Available”.

    XSLT 2.0 Stylesheet:

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output indent="yes"/>
      <xsl:strip-space elements="*"/>
    
      <xsl:param name="checkedOut" select="'Captain America|Thor'"/>
    
      <xsl:template match="node()|@*">
        <xsl:copy>
          <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="DVD[Name=tokenize($checkedOut,'\|')]">
        <xsl:copy>
          <xsl:apply-templates/>
          <status>Checked-Out</status>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="DVD">
        <xsl:copy>
          <xsl:apply-templates/>
          <status>Available</status>
        </xsl:copy>
      </xsl:template>  
    
    </xsl:stylesheet>
    

    applied to your example XML produces the following output:

    <Inventory>
       <DVD>
          <Name>Captain America</Name>
          <status>Checked-Out</status>
       </DVD>
       <DVD>
          <Name>Green Lantern</Name>
          <status>Available</status>
       </DVD>
       <DVD>
          <Name>Thor</Name>
          <status>Checked-Out</status>
       </DVD>
    </Inventory>
    

    Hope this helps.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has

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.