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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:22:33+00:00 2026-06-03T08:22:33+00:00

I am trying to filter a record set, and i have got it to

  • 0

I am trying to filter a record set, and i have got it to work with the following XSLT, but it doesnt look nice at all:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:r="http://www.castiron.com/response" exclude-result-prefixes="r">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:element name="Response">
            <xsl:element name="rcode">
                <xsl:text>0</xsl:text>
            </xsl:element>
            <xsl:element name="rmesage">
                <xsl:text>0</xsl:text>
            </xsl:element>
            <xsl:element name="payload">

                <xsl:for-each select="Response/payload/globalBuy[season='A09']">

                    <xsl:element name="season"><xsl:value-of select="season"/></xsl:element>
                    <xsl:element name="productId"><xsl:value-of select="productId"/></xsl:element>
                    <xsl:element name="globalBuyFlag"><xsl:value-of select="globalBuyFlag"/></xsl:element>

                </xsl:for-each>

            </xsl:element>
        </xsl:element>

    </xsl:template>

</xsl:stylesheet>

In addition i am seeing issues when a namespace pops up in the root. Sample XML below:

<?xml version="1.0" encoding="UTF8"?>
<Response xmlns="http://www.castiron.com/response">
    <payload>
        <globalBuy>
            <season>CD12</season>
            <productId>123456</productId>
            <globalBuyFlag>XXL</globalBuyFlag>
        </globalBuy>
    </payload>
</Response>
  • 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-03T08:22:34+00:00Added an answer on June 3, 2026 at 8:22 am

    You could certain simplify your code by removing all the uses of xsl:element. Unless you want the element name to be dynamically generated, it is much simple to just write out the element as normal XML. So instead of writing this….

    <xsl:element name="rcode">
        <xsl:text>0</xsl:text>
    </xsl:element> 
    

    Just write this…

    <rcode>0</rcode>
    

    As for filtering, if all you want to do is copy the XML, but only including certain items that match the filter, then you could override the identity template, and have templates matching the items you don’t want to include, and simply ignore them.

    Try this simplified XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="/Response">
          <xsl:copy>
             <xsl:apply-templates select="@*" />
             <rcode>0</rcode>
             <rmesage>0</rmesage>
             <xsl:apply-templates select="node()"/>
          </xsl:copy>
       </xsl:template>
    
       <xsl:template match="globalBuy[not(season='A09')]" />
    
       <xsl:template match="@*|node()">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>   
    </xsl:stylesheet>
    

    When applied to the following XML

    <Response>
       <payload>
          <globalBuy>
             <season>CD12</season>
             <productId>123456</productId>
             <globalBuyFlag>XXL</globalBuyFlag>
          </globalBuy>
          <globalBuy>
             <season>A09</season>
             <productId>123456b</productId>
             <globalBuyFlag>XXLb</globalBuyFlag>
          </globalBuy>
       </payload>
    </Response>
    

    Then the following is output

    <Response>
       <rcode>0</rcode>
       <rmesage>0</rmesage>
       <payload>
          <globalBuy>
             <season>A09</season>
             <productId>123456b</productId>
          <globalBuyFlag>XXLb</globalBuyFlag>
       </globalBuy>
       </payload>
    </Response>
    

    Do note I removed all namespaces in this example to keep things simpler.

    EDIT: If you do want to handle a default namespace, in XSLT 1.0 you would have explicity refer to the namespaces for each element you are matching. You would do something like this:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:r="http://www.castiron.com/response" exclude-result-prefixes="r">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="/r:Response">
          <xsl:copy>
             <rcode xmlns="http://www.castiron.com/response">0</rcode>
             <rmesage xmlns="http://www.castiron.com/response">0</rmesage>
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>
    
       <xsl:template match="r:globalBuy[not(r:season='A09')]" />
    
       <xsl:template match="@*|node()">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>   
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to filter some XML in JavaScript using E4X and have some specific
I have a LINQ result set I'm trying to filter in a strange and
I've got myself in a right mess following all kinds of semi-relevant tutorials trying
I'm trying to find all records in database that have exactly the same set
I'm trying to filter a set of records based on a sub-object's criteria. This
I have a table that contains unfortuantely bad data and I'm trying to filter
I'm trying to filter my list of auditions by show ID but when the
I'm trying to use WMAudio Encoder DMO filter to record captured sound from the
I'm trying to create a new EventPlace for an Event record. I have Event
I have been fruitlessly trying for several hours to make a function that filter

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.