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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:42:35+00:00 2026-05-21T07:42:35+00:00

I’m looking for a way (if it’s even possible) of using an XSL transform

  • 0

I’m looking for a way (if it’s even possible) of using an XSL transform of an XSD document to remove unused elements. This comes up a lot in my job where a company will define an XSD with absolutely everything in it, but then they will want to create a cut-down version for a single root element within it.

To explain further, I might have an XSD like the following:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="RootElement">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="ChildElement"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="ChildElement"/>
    <xs:element name="UnusedElement"/>
</xs:schema>

What I would like to be able to do is to set up an XSL where I provide the starting element (in this case RootElement) and it will copy over all dependent elements but omit the unused ones. In the above example, if I passed in RootElement I’d expect to see RootElement and ChildElement included but UnusedElement omitted.

(When I say “provide the starting element”, I’m quite happy to crack open the stylesheet and type xsl:template match="RootElement" where required.)

This would obviously have to be recursive, so would navigate the entire structure defined below the starting element, and any element in that schema that was not used would be discarded.

(Of course, it would be even better if it could do the same in any imported schemas!)

I’ve searched Google extensively and can’t find anything on this – I’m not sure if that means it’s not possible or not.

Thanks!

Edit: Actually I probably should clarify and say that I would like to remove unused elements AND types, so it would follow both ref="childElement" and type="someType" links.

  • 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-21T07:42:35+00:00Added an answer on May 21, 2026 at 7:42 am

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema" >
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:param name="ptopElementName" select="'RootElement'"/>
    
     <xsl:variable name="vTop" select=
     "/*/xs:element[@name=$ptopElementName]"/>
    
     <xsl:variable name="vNames"
          select="$vTop/descendant-or-self::*/@name"/>
    
     <xsl:variable name="vRefs"
          select="$vTop/descendant-or-self::*/@ref"/>
    
     <xsl:variable name="vTypes"
          select="$vTop/descendant-or-self::*/@type"/>
    
     <xsl:template match="node()|@*" name="identity">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="xs:element">
      <xsl:if test=
        "@name=$vNames
        or
         @name=$vRefs
        or
         ancestor-or-self::*[@name=$ptopElementName]">
       <xsl:call-template name="identity"/>
      </xsl:if>
     </xsl:template>
    
     <xsl:template match="xs:complexType|xs:simpleType">
      <xsl:if test=
       "@name=$vTypes
        or
         ancestor-or-self::*[@name=$ptopElementName]">
       <xsl:call-template name="identity"/>
      </xsl:if>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xs:element name="RootElement">
            <xs:complexType>
                <xs:sequence>
                    <xs:element ref="ChildElement"/>
                </xs:sequence>
            </xs:complexType></xs:element>
        <xs:element name="ChildElement"/>
        <xs:element name="UnusedElement"/>
    </xs:schema>
    

    produces the wanted, corect result:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
       <xs:element name="RootElement">
          <xs:complexType>
             <xs:sequence>
                <xs:element ref="ChildElement"/>
             </xs:sequence>
          </xs:complexType>
       </xs:element>
       <xs:element name="ChildElement"/>
    </xs:schema>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.